Skip to content

Instantly share code, notes, and snippets.

@ChristianKienle
Created August 12, 2012 15:52
Show Gist options
  • Select an option

  • Save ChristianKienle/3332404 to your computer and use it in GitHub Desktop.

Select an option

Save ChristianKienle/3332404 to your computer and use it in GitHub Desktop.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserverForName:SISPersistentStoreNotifications.didImportUbiquitousContentChanges object:nil queue:nil usingBlock:^(NSNotification *note) {
CMKUbiquitousChange *change = [note.userInfo objectForKey:@"ubiquitousChange"];
NSArray *insertedObjectIDs = change.insertedObjectIDs;
NSMutableArray *insertedObjects = [NSMutableArray array];
for(NSManagedObjectID *objectID in insertedObjectIDs)
{
NSManagedObject *object = [self.managedObjectContext objectWithID:objectID];
if(object == nil)
{
continue;
}
[insertedObjects addObject:object];
}
NSDictionary *userInfo = @{NSInsertedObjectsKey : insertedObjects};
NSNotification *didSaveNotification = [NSNotification notificationWithName:NSManagedObjectContextDidSaveNotification object:self userInfo:userInfo];
[self.managedObjectContext performBlock:^{
[self.managedObjectContext mergeChangesFromContextDidSaveNotification:didSaveNotification];
}];
}];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment