Consuming Changes from iCloud

Whether we’re using a standard Core Data stack or a UIManagedDocument, we need to know when changes come in from iCloud. Changes will always come in asynchronously, and our NSManagedObjectContext won’t know about them. It is our responsibility to notify our NSManagedObjectContext of any incoming changes. To do that, we first need to listen for the change notification via the NSNotificationCenter.

  NSString *name = nil;
  name = NSPersistentStoreDidImportUbiquitousContentChangesNotification;
  NSManagedObjectContext *moc = [[self dataController] managedObjectContext];
  [center addObserver:self
  selector:​@selector​(mergePSCChanges:)
  name:name
  object:[moc persistentStoreCoordinator]]; ...

Get Core Data in Objective-C, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.