【发布时间】:2016-07-01 16:37:36
【问题描述】:
我有一个简单的课程
class FarmRecord: Object {
dynamic var year = ""
dynamic var month = ""
dynamic var day = ""
func setYearID(inYear: String) {
self.year = inYear
compoundKey = compoundKeyValue()
}
func setMonthID(inMonth: String) {
self.month = inMonth
compoundKey = compoundKeyValue()
}
func setDayID(inDay: String) {
self.day = inDay
compoundKey = compoundKeyValue()
}
dynamic lazy var compoundKey: String = self.compoundKeyValue()
private func compoundKeyValue() -> String {
return "\(year)\(month)\(day)"
}
override static func primaryKey() -> String? {
return "compoundKey"
}
}
我尝试添加对象如下:
let storeRealm = try! Realm()
let farm = FarmRecord()
farm.setYearID("2016")
farm.setMonthID("3")
farm.setDayID("1")
do {
try storeRealm.write {
storeRealm.add(farm)
}
} catch {
}
我看到EXEC_BAD_ACCESS (code = 1) 发生崩溃。我什至试过storeRealm.add(farm, update: true),没有任何区别。
【问题讨论】:
标签: swift primary-key realm