first I create a NSFetchedResultsController
with a NSFetchRequest
that fetches all object of entity "Entity".
and then I insert an new NSManagedObject A ,which is an instance of "Entity", and Edit B, which is also an instance of "Entity".
then I call NSArray *result = [fetchedResultsController -fetchedObjects]
, will A and B in result?
Throughout the project, I use only one NSManagedObjectContext.
if I do, what does this mean in its Document?
fetchedObjects The results of the fetch.
@property (nonatomic, readonly) NSArray *fetchedObjects Discussion The value of the property is nil if performFetch: hasn’t been called.
The results array only includes instances of the entity specified by the fetch request (fetchRequest) and that match its predicate. (If the fetch request has no predicate, then the results array includes all instances of the entity specified by the fetch request.)
The results array reflects the in-memory state of managed objects in the controller’s managed object context, not their state in the persistent store. The returned array does not, however, update as managed objects are inserted, modified, or deleted.
The meaning of the last sentence
... The returned array does not, however, update as managed objects are inserted, modified, or deleted.
is (based on my experiments): If you store a reference to the fetched objects
NSArray *result = [fetchedResultsController fetchedObjects];
then this array referenced by result
will not update if objects are inserted, modified or deleted.
So the emphasis is on "the returned array does not ...".
But if you call
[fetchedResultsController fetchedObjects]
later again, the return value is a new list of objects, including the changes.
More precisely: If you have set a delegate, the FRC tracks changes to the managed object context and calls the FRC delegate functions. The delegate functions are not called immediately when objects are inserted/modified/deleted, but either
As soon as controllerDidChangeContent:
is called, a new call to [fetchedResultsController fetchedObjects]
returns the updated object list.
@Dwayne use [fetchedResultsController.managedObjectContext processPendingChanges]
after your insert/delete/update if you want instant update on your delegate object, normally it is invoked at the end of the runloop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With