Introduction . . . . . . . . . . . . . ix
1. Under the Hood of Core Data . . . . . . . . . 1
1.1 NSManagedObjectModel 1
1.2 NSPersistentStoreCoordinator 5
1.3 NSManagedObjectContext 8
1.4 NSManagedObject 10
1.5 NSFetchRequest 17
1.6 NSSortDescriptor 20
1.7 Fetched Properties 21
1.8 Wrapping Up 21
2. iOS: NSFetchedResultsController . . . . . . . 23
2.1 How to Use the NSFetchedResultsController 23
2.2 Under the Hood of the NSFetchedResultsController 31
2.3 Building Our Own: ZSContextWatcher 32
2.4 Wrapping Up 36
3. Versioning and Migration . . . . . . . . . 37
3.1 Some Maintenance Before We Migrate 38
3.2 A Simple Migration 39
3.3 The Difference Between Light and Heavy Migrations 42
3.4 A Heavy/Manual Migration 44
3.5 Fundamentals of Core Data Versioning 51
3.6 Progressive Data Migration (An Academic Exercise) 54
3.7 Wrapping Up 59
4. Performance Tuning . . . . . . . . . . . 61
4.1 Persistent Store Types 61
4.2 Optimizing Your Data Model 63
4.3 Fetching 67
4.4 Faulting 71
4.5 Access Patterns 75
4.6 Wrapping Up 76
5. Threading . . . . . . . . . . . . . 77
5.1 Why Isn’t Core Data Thread-Safe? 77
5.2 Creating Multiple Contexts 78
5.3 Exporting Recipes 81
5.4 Importing Recipes 87
5.5 Parent-Child NSManagedObjectContext Instances 92
5.6 Wrapping Up 98
6. Using iCloud . . . . . . . . . . . . 99
6.1 Introducing the UIManagedDocument 100
6.2 Direct NSManagedObjectContext to iCloud 106
6.3 Consuming Changes from iCloud 109
6.4 Under the Hood 110
6.5 Migrating an Existing Application 113
6.6 Desktop iCloud Integration 116
6.7 Data Quantities 118
6.8 Sharing Data Between iOS and OS X 119
6.9 Wrapping Up 120
7. Adding a Desktop Foundation . . . . . . . . 121
7.1 Our Application 121
7.2 Our Application Design 122
7.3 Sharing the Data Model 122
7.4 Building the Controller Layer 123
7.5 Building the User Interface 126
7.6 Adding a Splash of Code 132
7.7 Wrapping Up 135
8. OS X: Bindings, KVC, and KVO . . . . . . . . 137
8.1 Key Value Coding 137
8.2 Key Value Observing 142
8.3 Cocoa Bindings and Core Data 143
8.4 Other Interface Elements That Use KVO, KVC, and Core
Data 147
8.5 Wrapping Up 151
9. Spotlight, Quick Look, and Core Data . . . . . . 153
9.1 Integrating with Spotlight 154
9.2 Integrating with Quick Look 168
Contents • vi
9.3 Putting It All Together 176
9.4 Wrapping Up 176
10. Dynamic Parameters . . . . . . . . . . 179
10.1 Building the Xcode Example Project 181
10.2 The DocumentPreferences Object 181
10.3 Wrapping Up 186
11. Distributed Core Data . . . . . . . . . . 189
11.1 Building the Server 190
11.2 Building the Client 199
11.3 Testing the Networking Code 202
11.4 Wrapping Up 206
A1. Building a Foundation . . . . . . . . . . 209
A1.1 The Storyboard 209
A1.2 The Recipe List 211
A1.3 The Recipe Detail 213
A1.4 The Edit Workflow 214
A1.5 Ready for Core Data 219
A2. Macros in the Precompiled Header . . . . . . . 221
A2.1 Where Are the Macros? 221
A2.2 What Do They Do? 222
Bibliography . . . . . . . . . . . . 225
Index . . . . . . . . . . . . . . 227
Contents • vii