ios - Core Data NSFetchedResultsController not updated after a batchUpadate on the device but ok on simulator -
i have nsfetchedresultscontroller
managed uitableview
data source.
i trying modify property of nsmanagedobject
called amounttocompute
using nsbatchupdaterequest
. create batch update:
let batchupdate = nsbatchupdaterequest(entityname: "myentity") batchupdate.propertiestoupdate = ["amounttocompute" : newamount] batchupdate.resulttype = .updatedobjectidsresulttype
i execute it:
var batcherror: nserror? let batchresult = managedcontext.executerequest(batchupdate, error: &batcherror) as! nsbatchupdateresult?
and update current managed context, update each managedobject in managedcontext , perform new fetch of fetchedresultscontroller
:
if let result = batchresult { let objectids = result.result as! [nsmanagedobjectid] objectid in objectids { let managedobject: nsmanagedobject = managedcontext.objectwithid(objectid) if !managedobject.fault { managedcontext.refreshobject(managedobject, mergechanges: true) } if !fetchedresultscontroller.performfetch(&error) { println("error: + \(error?.localizeddescription), \(error!.userinfo)") } } }
i implemented methods of delegate nsfetchedresultscontrollerdelegate
manage changes in results sent nsfetchedresultscontroller
:
func controllerwillchangecontent(controller: nsfetchedresultscontroller) { tableview.beginupdates() } func controller(controller: nsfetchedresultscontroller, didchangeobject anobject: anyobject, atindexpath indexpath: nsindexpath?, forchangetype type: nsfetchedresultschangetype, newindexpath: nsindexpath?) { switch type { ... case .update: reloadrowsatindexpaths([indexpath!], animation: reloadrowswithanimation) let mymanagedobject = anobject as! mymanagedobject println("update : \(mymanagedobject.amounttocompute)") ... } } func controllerdidchangecontent(controller: nsfetchedresultscontroller) { tableview.endupdates() }
i run app on 8.4 ios simulator , goes fine. println("update : \(mymanagedobject.amounttocompute)")
prints new value.
i run app on iphone 6 8.4.1 , value not updated, println("update : \(mymanagedobject.amounttocompute)")
prints old value. new value saved changes don't appear in table view while on simulator.
what's wrong? how come can different whether i'm on simulator or on device. versions not same doubt apple touched core data architecture in last update.
this unusual, known problem ran myself , spent couple of days pulling out hair until found blog post, worked me.
it boiled down adding single line of code set staleness interval zero:
[context setstalenessinterval:0];
if i'm reading post right you're having same issue. :)
Comments
Post a Comment