Swift 具有惰性属性的域中的复合键
我在Swift中找到了使用带复合主键的领域的伟大解决方案: 但我发现Realm不支持惰性属性,在我的例子中,我收到以下错误: 异常NSException*名称:“RLMEException”-原因:“在域Swift对象类上不允许使用惰性托管属性‘compoundKey’。请将该属性添加到“忽略的属性”列表中,或将其设置为非惰性。”0x00007f8a05108060Swift 具有惰性属性的域中的复合键,swift,realm,compound-key,Swift,Realm,Compound Key,我在Swift中找到了使用带复合主键的领域的伟大解决方案: 但我发现Realm不支持惰性属性,在我的例子中,我收到以下错误: 异常NSException*名称:“RLMEException”-原因:“在域Swift对象类上不允许使用惰性托管属性‘compoundKey’。请将该属性添加到“忽略的属性”列表中,或将其设置为非惰性。”0x00007f8a05108060 是否仍然可以使用没有lazy属性的复合键?您找到的解决方案已过时。我会在那里留个条子。我建议删除lazy修饰符,并将compoun
是否仍然可以使用没有lazy属性的复合键?您找到的解决方案已过时。我会在那里留个条子。我建议删除
lazy
修饰符,并将compoundKey
初始化为空字符串
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)"
}
}