caiyue1993 / IceCream

Sync Realm Database with CloudKit
MIT License
1.93k stars 243 forks source link

Primary key Support ObjectId ( Realm - ObjectId.generate()) #239

Closed WelkinDev closed 3 years ago

WelkinDev commented 3 years ago

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 3 years ago

Or use ObjectId.generate().stringValue, will it cause other problem?

mohitnandwani commented 3 years ago

You can useUUID().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 3 years ago

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