I have a simple class
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 {
retu "(year)(month)(day)"
}
override static func primaryKey() -> String? {
retu "compoundKey"
}
}
I tried to add object as follow:
let storeRealm = try! Realm()
let farm = FarmRecord()
farm.setYearID("2016")
farm.setMonthID("3")
farm.setDayID("1")
do {
try storeRealm.write({ () -> Void in
storeRealm.add(farm)
})
} catch {
}
And I got EXEC_BAD_ACCESS (code = 1), error I even tried storeRealm.add(farm, update: true) with no difference
I should work but it didn't. Please help
