2
我发现这个伟大的解决方案,用于斯威夫特利用领域具有复合主键:https://github.com/realm/realm-cocoa/issues/1192复合键懒财产
public final class Card: Object {
public dynamic var id = 0 {
didSet {
compoundKey = compoundKeyValue()
}
}
public dynamic var type = "" {
didSet {
compoundKey = compoundKeyValue()
}
}
public dynamic lazy var compoundKey: String = self.compoundKeyValue()
public override static func primaryKey() -> String? {
return "compoundKey"
}
private func compoundKeyValue() -> String {
return "\(id)-\(type)"
}
}
但我发现,境界不支持懒惰性,在我来说,我收到此错误:
exception NSException * name: "RLMException" - reason: "Lazy managed property 'compoundKey' is not allowed on a Realm Swift object class. Either add the property to the ignored properties list or make it non-lazy." 0x00007f8a05108060
是否仍然有可能没有惰性属性的复合键?