Dynamic properties in Realm

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 and RealmOptional 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 with let.

The dynamic keyword is what allows for Realm to be notified of changes to model variables, and consequently reflect them to the database.


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 = ""

Tags:

Ios

Swift2

Realm