Created
September 20, 2012 20:43
-
-
Save acenqiu/3758238 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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