警告:我是iOS,Swift和Realm的新手。使用Realm保存和檢索時沒有問題,但似乎無法在不崩潰的情況下更新現有對象。試圖在swift中更新領域對象時獲取SIGABRT
的AppDelegate:
class Bale: Object {
dynamic var uid = NSUUID().UUIDString
dynamic var id = 0
dynamic var number = 0
dynamic var type = 0
dynamic var weight = 0
dynamic var size = ""
dynamic var notes = ""
override static func primaryKey() -> String? {
return "uid"
}
}
在別處:(Xcode中堅持所有的!)
let bale: Bale = getBaleByIndex(baleSelected)
bale.id = Int(textID.text!)!
bale.number = Int(textNumber.text!)!
bale.type = Int(textType.text!)!
bale.weight = Int(textWeight.text!)!
bale.size = textSize.text!
bale.notes = textNotes.text!
try! realm.write {
realm.add(bale, update: true)
}
getBaleByIndex:
func getBaleByIndex(index: Int) -> Bale {
return bales[index]
}
我從getBaleByIndex返回罷了對象讀取數據在其他地方,這樣的功能正常工作。我在上得到了SIGABRT類AppDelegate:UIResponder,UIApplicationDelegate {。沒有完整的示例顯示領域文檔或示例中的更新。我也嘗試使用realm.create和適當的參數,但仍然是不行。它看起來很簡單,所以我確信我在做一些愚蠢的事情。任何幫助都會很棒。謝謝!
見http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1 – rmaddy
你是如何加入第一次的對象?你在哪裏得到這種捆包陣列?共享更多代碼可能會有所幫助 – Shripada