ICloud and basic data. NSFetchedResultsController does not update at initial synchronization

iCloud and Core Data work great. With the exception of...

When you start the first application (there is existing iCloud data), NSFetchedResultsControllers are not updated as the data is received. NSFetchedResultsController representatives are simply not called. When the application is terminated and resumed, all data is there, as it should be.

The kernel data code is the same as a great tutorial here . I have a feeling that this code is not mistaken, since I used it for another application and did not have this problem.

Additional information: The context of my managed entity is initialized by the main concurrency queue. The only thing that I managed to find out is that I can catch the source data as it appears - the function below is called a few seconds after the application starts. However, despite the data, the existing controllers of the obtained results do not seem to be updated accordingly (but their creation again shows the data).


- (void)storesWillChange:(NSNotification *)notification { NSManagedObjectContext *context = self.managedObjectContext; [context performBlockAndWait:^{ NSError *error; if ([context hasChanges]) { BOOL success = [context save:&error]; if (!success && error) { // perform error handling NSLog(@"%@",[error localizedDescription]); } } [context reset]; }]; } 


So:. What can I do to start figuring out why NSFetchedResultsControllers are not updated, how should they be?

+7
ios objective-c iphone ipad core-data
source share
2 answers

I have a little guess here, but I think because you immediately restore the context after saving that the NSFetchedResultsController delegation methods are not going to do this because of a reset. I mean, delegate methods are designed to solve tasks such as selecting records that change in the current result set (inserting, updating, or deleting records that are currently tracked by the recipient).

When you execute the reset context, you delete all of this, and therefore these delegate methods are not called, because what they track no longer exists in the form that it recognizes.

Whenever I reset is a context due to incoming iCloud updates, I usually guarantee that I recreate my selected result controller for the new reset context.

Forcing an application to shut down will cause the set result handler to recreate when you restart it, therefore, showing the data as you expect to see.

+9
source share

Initialize the managed object context when the application starts. and then sync with iCloud and reload the table, it will work fine. I also did the same when I have the same problem as you.

0
source share

All Articles