O'Reilly logo

Core Data in Swift by Marcus S. Zarra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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’s our responsibility to notify our NSManagedObjectContext of incoming changes. To do that, we need to listen for the change notification via the NSNotificationCenter.

 let​ center = ​NotificationCenter​.​default
 center.addObserver(​self​, selector: ​#​selector(mergePSCChanges(_:)),
  name: .​NSPersistentStoreDidImportUbiquitousContentChanges​,
  object: mainContext)

Just like with the UIDocumentStateChangedNotification for the UIManagedDocument, it’s a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required