Using Document Preferences

With this design, we can access our parameters within each document without having to worry about the underlying structure. We also don’t need to stop coding just to hop over and add a parameter to the object. We can work with DocumentPreferences in the same manner that we work with NSUserDefaults.

This same design can be used in a nondocument application by changing the DocumentPreferences object by directly adding the methods ‑valueForUndefinedKey: and ‑setValue:forUndefinedKey: to the NSApplicationDelegate along with the NSManagedObjectContext.

Whether or not we’re working in a document model, we can now access persistent store--specific parameters with a single call similar to the following:

 NSString *value = ...

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.