ios - composite primary key realm/swift -
i'm new swift , realm. want make composite primary key , when i'm trying :
class dblocation : object { dynamic var id = 0 dynamic var tourid = 0 dynamic var uuid : string { return "\(id)\(tourid)" } override static func primarykey() -> string? { return "uuid" } } i'm getting error : 'primary key property 'uuid' not exist on object 'dblocation'
anyone can me out example how create composite primary key ?
this should give answer:
class dblocation: object { dynamic var id = 0 dynamic var tourid = 0 func setcompoundid(id: int) { self.id = id compoundkey = compoundkeyvalue() } func setcompoundtourid(tourid: int) { self.tourid = tourid compoundkey = compoundkeyvalue() } dynamic lazy var compoundkey: string = self.compoundkeyvalue() override static func primarykey() -> string? { return "compoundkey" } func compoundkeyvalue() -> string { return "\(id)\(tourid)" } } the custom setters make sure, compoundkey updated, lazy key word makes sure first time access it, derived you've set.
find out more on topic in this thread issue has been debated.
Comments
Post a Comment