Need a little assistance regarding @Persisted vs @objc dynamic

That’s not really valid code so stick with @Persisted var coll : Int?

A bit of explanation may help; Realm has it’s roots in ObjC. Over time, Swift came into play and support for that developed. Initially, properties in Swift would be defined like this

@objc dynamic var someInt = 0 // non optional Int
let someOptionalInt = RealmProperty<Int?>() //optional Int

but that wasn’t very Swift like. As things progressed Realm was simplified and retrofitted to more align with Swift naming conventions and style. That change happend at Realm 10.10.

So from 10.10 forward properties look more Swift like

@Persisted var intName: Int //non-optional Int
@Persisted var optIntName: Int? //optional Int

You should be using @Persisted to define all Realm properties as shown in the Supported Types documentation.

1 Like