2016-06-24 69 views
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

是否仍然有可能沒有惰性屬性的複合鍵?

回答

6

您發現的解決方案已過時。我會留下一個關於那裏的筆記。我建議刪除lazy修飾符並將compoundKey初始化爲空字符串。