this error:
coredata: error: serious application error. exception caught delegate of nsfetchedresultscontroller during call -controllerdidchangecontent:. attempt delete , reload same index path ( {length = 2, path = 0 - 0}) userinfo (null)
this typical nsfetchedresultscontrollerdelegate:
func controllerwillchangecontent(controller: nsfetchedresultscontroller) { tableview.beginupdates() } func controller(controller: nsfetchedresultscontroller, didchangesection sectioninfo: nsfetchedresultssectioninfo, atindex sectionindex: int, forchangetype type: nsfetchedresultschangetype) { let indexset = nsindexset(index: sectionindex) switch type { case .insert: tableview.insertsections(indexset, withrowanimation: .fade) case .delete: tableview.deletesections(indexset, withrowanimation: .fade) case .update: fallthrough case .move: tableview.reloadsections(indexset, withrowanimation: .fade) } } func controller(controller: nsfetchedresultscontroller, didchangeobject anobject: nsmanagedobject, atindexpath indexpath: nsindexpath?, forchangetype type: nsfetchedresultschangetype, newindexpath: nsindexpath?) { switch type { case .insert: if let newindexpath = newindexpath { tableview.insertrowsatindexpaths([newindexpath], withrowanimation: .fade) } case .delete: if let indexpath = indexpath { tableview.deleterowsatindexpaths([indexpath], withrowanimation: .fade) } case .update: if let indexpath = indexpath { tableview.reloadrowsatindexpaths([indexpath], withrowanimation: .none) } case .move: if let indexpath = indexpath { if let newindexpath = newindexpath { tableview.deleterowsatindexpaths([indexpath], withrowanimation: .fade) tableview.insertrowsatindexpaths([newindexpath], withrowanimation: .fade) } } } } func controllerdidchangecontent(controller: nsfetchedresultscontroller) { tableview.endupdates() } in viewdidload():
private func setuponcefetchedresultscontroller() { if fetchedresultscontroller == nil { let context = nsmanagedobjectcontext.mr_defaultcontext() let fetchreguest = nsfetchrequest(entityname: "dborder") let datedescriptor = nssortdescriptor(key: "date", ascending: false) fetchreguest.predicate = nspredicate(format: "user.identifier = %@", dbappsettings.currentuser!.identifier ) fetchreguest.sortdescriptors = [datedescriptor] fetchreguest.fetchlimit = 10 fetchedresultscontroller = nsfetchedresultscontroller(fetchrequest: fetchreguest, managedobjectcontext: context, sectionnamekeypath: "identifier", cachename: nil) fetchedresultscontroller.delegate = self try! fetchedresultscontroller.performfetch() } }
this seems bug in ios 9 (which still beta) , discussed in apple developer forum
i can confirm problem ios 9 simulator xcode 7 beta 3. observed updated managed object, didchangeobject: delegate method called twice: once nsfetchedresultschangeupdate event , again nsfetchedresultschangemove event (and indexpath == newindexpath).
adding explicit check indexpath != newindexpath suggested in above thread seems solve problem:
case .move: if indexpath != newindexpath { tableview.deleterowsatindexpaths([indexpath!], withrowanimation: .fade) tableview.insertrowsatindexpaths([newindexpath!], withrowanimation: .fade) }
Comments
Post a Comment