How to set primary key in Swift for Realm model
primaryKey
needs to be a class function which returns the name of the property which is the primary key, not an instance method which returns the value of the primary key.
@objcMembers class Foo: RLMObject { dynamic var id = 0 dynamic var title = "" override class func primaryKey() -> String? { return "id" }}