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

Notifying the Application of Changes

Now that we’ve made changes on disk, we need to notify the contexts of them.

In this example, it’s not strictly necessary. Most likely the user interface hasn’t touched any of these objects yet. If the objects haven’t been loaded into memory, then there’s no risk of a conflict. However, it’s best that we don’t assume they haven’t been loaded yet. Users can be very clever.

There are two basic ways to notify our NSManagedObjectContext instances of the changes. We can reset each object individually in each NSManagedObjectContext that it might be associated with, or we can use the new API that was added in iOS 9.0. Let’s look at the harder way first.

Manual Object Refreshing

If the situation calls for it, we ...

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