Skip to content

Instantly share code, notes, and snippets.

@acenqiu
Created September 20, 2012 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acenqiu/3758238 to your computer and use it in GitHub Desktop.
Save acenqiu/3758238 to your computer and use it in GitHub Desktop.
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
if (type == NSFetchedResultsChangeUpdate) {
[[cachedTHJobs objectAtIndex:indexPath.row] refresh];
}
}
- (void)registerNotifications
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(backgroundContextSaved:)
name:NSManagedObjectContextDidSaveNotification
object:self.context.parentContext];
[center addObserver:self
selector:@selector(backgroundContextChanged:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:self.context.parentContext];
}
- (void)backgroundContextSaved:(NSNotification *)notification
{
[self.context mergeChangesFromContextDidSaveNotification:notification];
}
- (void)backgroundContextChanged:(NSNotification *)notification
{
NSArray *updatedObjects = [notification.userInfo valueForKey:NSUpdatedObjectsKey];
for (Moment *item in updatedObjects) {
[self.context performBlockAndWait:^{
NSError *error = nil;
Moment *moment = (Moment *)[self.context existingObjectWithID:item.objectID error:&error];
moment.progress = item.progress;
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment