Primary key Support ObjectId ( Realm - ObjectId.generate())
WelkinDev opened this issue · 3 comments
WelkinDev commented
Behavior:
As I use ObjectId as primary key, app will crash when set CreamAsset property
Suggestion:
Try to pass ObjectId as String or Int when use ObjectId as primary key, and exchange to ObjectId after sync complete
WelkinDev commented
Or use ObjectId.generate().stringValue, will it cause other problem?
mohitnandwani commented
You can use UUID().uuidString
instead for generating random ids if ObjectID.generate is causing any issues. Other than that, how are you setting the primary key? AFAIK only int and string primary values are currently supported.
WelkinDev commented
UUID().uuidString
method I used before, but some strange problems can occur on MacOS. ObjectId.generate()
is fine.
Now the code looks like this, Everything seems normal now.
@objc dynamic var identifier = ObjectId.generate().stringValue
override class func primaryKey() -> String? { return "identifier" }