ios - Object returned from fetch request has incorrect data -


i attempting object fetch request, , checking property of object.

depending on type property cause me display notification or not. after making successful connection, set property type of object 'updated' 'inserted.' then, when refresh view, pull objects coredata , check properties 'updated' type. problem having objects returned in fetch request attempted change 'updated' still display old 'inserted' value fetch request, don't after submission. reverting. (and saving context)

what more confusing have gotten program @ actual tables in database file stored on device, , shows correct value of updated in table. fetch request still comes object having incorrect data. , no amount of refreshing fixes issue.

how can fetch request giving me objects old/incorrect data when coredata file shows tables correct values?

 // code fetch request  // return array of assets specific customer nsfetchrequest *fetchreq = [nsfetchrequest fetchrequestwithentityname:@"asset"]; fetchreq.predicate = [nspredicate predicatewithformat:@"customerid = %@" argumentarray:[nsarray arraywithobject:customerid]]; nsarray *results = [[coredatamanager sharedmanager] executefetchrequest:fetchreq];  return results;  //executefetchrequest method nsmanagedobjectcontext *context = [self managedobjectcontextforcurrentthread]; nsarray *results = [context executefetchrequest:fetchrequest error:&error]; return results; 

@arcanfel's suggestion (in comments original question) helped me find solution own problem, hidden in 'show more comments' section.

it have been helpful see answer, not comment, i've taken comment , expanded little.

original comment:

[self managedobjectcontextforcurrentthread] - think can cause problem, different contexts can have different version of nsmanagedobjects. can call [fetchreq setshouldrefreshrefetchedobjects:yes] , return up-to-date version of objects

whilst using setshouldrefreshrefetchedobjects:yes didn't resolve problem of subsequent fetch requests not bringing right data, did make me @ context management.

in 1 method setting context, , reading data. in method setting context, reading data, altering , saving context... different context first method had.

in short, careful you're referring same context or update in context1 won't in synch retrieve context2.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -