Reputation: 4886
I am starting to work with Realm on iOS 8 or greater and looking at the documentation in Realm. I noticed that all of the properties have the dynamic
keyword in front of them. Is that required in Realm? I have read the Apple documentation on the keyword which can be found here. https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.html
Upvotes: 25
Views: 8318
Reputation: 2914
In Swift 3, we declared our property like this
dynamic var Name : String = ""
In Swift 4, we declared our property like this
@objc dynamic var Name : String = ""
Upvotes: 1
Reputation: 5605
Yes, it is mandatory for normal var
properties. From the realm docs.
Realm model properties need the
dynamic var
attribute in order for these properties to become accessors for the underlying database data.There are two exceptions to this:
List
andRealmOptional
properties cannot be declared as dynamic because generic properties cannot be represented in the Objective-C runtime, which is used for dynamic dispatch of dynamic properties, and should always be declared withlet
.
The dynamic keyword is what allows for Realm to be notified of changes to model variables, and consequently reflect them to the database.
Upvotes: 39