core data - NSFetchedResultsController with predicate ignores changes merged from different NSManagedObjectContext -
i presenting table view contents using nsfetchedresultscontroller
has predicate:
[nspredicate predicatewithformat:@"visible == %@", [nsnumber numberwithbool:yes]]
on background thread using separate nsmanagedobjectcontext
update few of entities , change theirs visible
value no
yes
. save, merge changes in main thread's nsmanagedobjectcontext
. nsfetchedresultscontroller
's fetchedobjects
doesn't change. controller doesn't call -controller:didchangeobject:...
on delegate. if entities updated on main thread in identical manner (my test app calls same method), works expected.
also notification's nsupdatedobjectskey
contains objects.
currently solutions i've found call each of nsupdatedobjectskey
entities:
nsmanagedobjectcontext *context = ... // main thread context [context existingobjectwithid:[object objectid] error:nil]
this issue updated objects didn't match predicate.
am missing obvious?
turns out main nsmanagedobjectcontext
didn' t event fire nsmanagedobjectcontextobjectsdidchangenotification
updated objects because not done faulted objects.
generic fix (or keep track of object ids needs treatment):
nsmanagedobjectcontext *context = [self managedobjectcontext]; for(nsmanagedobject *object in [[notification userinfo] objectforkey:nsupdatedobjectskey]) { [[context objectwithid:[object objectid]] willaccessvalueforkey:nil]; } [context mergechangesfromcontextdidsavenotification:notification];
from nsmanagedobject class reference:
you can invoke method key value of nil ensure fault has been fired, illustrated following example.
Comments
Post a Comment