Definition from Objective-c if the Swift property is declared as dynamic

For some time I tried to check the Swift class and determine if any of the properties is declared dynamic. My class class is as follows:

class SwiftTestClass : DBObject {

    dynamic var SwiftTestString : String!
    dynamic var SwiftTestNumber : NSNumber!
    dynamic var lowercaseField : String!
    var nonDynamicVariable : String!

    func testThyself() {

        SwiftTestClass.query().fetchLightweight().removeAll()

        let newObject = SwiftTestClass();
        newObject.SwiftTestString = "hello, world"
        newObject.SwiftTestNumber = 123
        newObject.lowercaseField = "lowercase"
        newObject.nonDynamicVariable = "should not be persisted"
        newObject.commit()

        let result = SwiftTestClass.query().fetch().firstObject;
        print(result)

    }

}

I basically try to choose the fact that the property is nonDynamicVariablenot declared dynamic, like the rest.

DBObject is a subclass NSObject.

I tried:

  • Looking at the type of property encoding, they are identical (type for type)
  • Seeing whether they have a difference in the implementation of the method, they do not. (e.g. class_getMethod) dynamic properties still have getter / setter methods.
  • Capture the Ivars to see if there is a difference.
  • View all property attributes that are also identical.

What i know:

  • class_replaceMethod <propertyName>/set<propertyName>, ( , objc), ( ?, , !) .

- , swift objc?

+4

Source: https://habr.com/ru/post/1612093/


All Articles