This is the first Core Data book to fully reflect Apple’s latest platform innovations, including its dramatic recent improvements to iCloud support. Hands-on from start to finish, it teaches you step-by-step as you create a modern data-driven iOS app using Storyboards, ARC, iOS 7, and Xcode 5. Tim Roadley introduces new patterns and best practices designed to overcome the frustrations of Core Data development. One step at a time, you’ll build and extend your skills even mastering advanced techniques such as complex model migration, deep copy, background processing, and integration with Dropbox, StackMob, and iCloud. Table of Contents 8 Preface 16 1 Your First Core Data Application 22 What Is Core Data? 22 Persistent Store Coordinator 23 Managed Object Model 25 Managed Object Context 25 When to Use Core Data 26 Introducing Grocery Dude 26 Adding Core Data to an Existing Application 27 Introducing Core Data Helper 28 Core Data Helper Implementation 30 Files 30 Paths 31 Setup 32 Saving 35 Summary 37 Exercises 37 2 Managed Object Model Basics 40 What Is a Managed Object Model? 40 Adding a Managed Object Model 41 Entities 41 Attributes 43 Integer 16/32/64 44 Float and Double 45 Decimal 46 String 46 Boolean 46 Date 46 Binary Data 47 Transformable 47 Attribute Settings 49 Subclassing NSManagedObject 50 Scalar Properties for Primitive Data Types 52 Snippet Demo Method 52 Creating a Managed Object 53 Backend SQL Visibility 54 Fetching Managed Objects 57 Fetch Request Sorting 59 Fetch Request Filtering 60 Fetch Request Templates 61 Deleting Managed Objects 63 Summary 64 Exercises 64 3 Managed Object Model Migration 66 Changing a Managed Object Model 66 Adding a Model Version 68 Lightweight Migration 69 Default Migration 73 Migration Manager 78 Summary 90 Exercises 90 4 Managed Object Model Expansion 92 Relationships 92 Delete Rules 98 Validation Errors 102 Entity Inheritance 107 Summary 111 Exercises 111 5 Table Views 112 Table Views 101 112 Core Data Table Views 114 Introducing CoreDataTVC 114 Fetching 116 DATASOURCE: UITableView 117 DELEGATE: NSFetchedResultsController 119 AppDelegate鈥檚 CoreDataHelper Instance 125 Introducing PrepareTVC 126 Data 127 View 129 Interaction 135 Introducing ShopTVC 138 Data 138 View 139 Interaction 142 Summary 143 Exercises 143 6 Views 146 Overview 146 The Target View Hierarchy 147 Introducing ItemVC 148 Keeping Reference to a Selected Item 149 Passing a Selected Item to ItemVC 149 Configuring the Scroll View and Text Fields 150 ItemVC Implementation 155 Interaction 155 DELEGATE: UITextField 157 View 158 Data 160 Units, Home Locations, and Shop Locations 164 Adding and Editing Units 166 Implementing UnitsTVC 168 Implementing UnitVC 170 Segue from UnitsTVC to UnitVC 174 Adding and Editing Home or Shop Locations 175 Configuring the Home Location Views 175 Configuring the Shop Location Views 177 Summary 179 Exercises 179 7 Picker Views 180 Overview 180 Introducing CoreDataPickerTF 181 DELEGATE+DATASOURCE: UIPickerView 183 Interaction 185 Data 186 View 186 Introducing UnitPickerTF 189 Creating the Unit Picker 191 Connecting the Unit Picker 192 Configuring ItemVC for the Unit Picker 192 Introducing LocationAtHomePickerTF 197 Introducing LocationAtShopPickerTF 199 Creating the Location Pickers 200 Connecting the Location Pickers 201 Configuring ItemVC for the Location Pickers 202 Picker-Avoiding Text Field 207 Summary 209 Exercises 209 8 Preloading Data 210 Default Data 210 Is an Import Required? 211 Importing from XML 214 Creating an Import Context 217 Preventing Duplicate Default Data 218 Triggering a Default Data Import 219 Introducing CoreDataImporter 221 Selecting Unique Attributes 226 Mapping XML Data to Entity Attributes 227 Importing from a Persistent Store 230 Using the Default Data Store as the Initial Store 231 Summary 234 Exercises 235 9 Deep Copy 236 Overview 236 Configuring a Source Stack 239 Configuring the Source Store 240 Enhancing CoreDataImporter 242 Object Info 242 Array For Entity 243 Copy Unique Object 244 Establish To-One Relationship 245 Establish To-Many Relationship 247 Establish Ordered To-Many Relationship 248 Copy Relationships 249 Deep Copy Entities 251 Triggering a Deep Copy 253 Summary 257 Exercises 257 10 Performance 260 Identifying Performance Issues 260 Implementing the Camera 261 Generating Test Data 266 Measuring Performance with SQLDebug 271 Measuring Performance with Instruments 272 Improving Performance 275 Clean Up 282 Summary 283 Exercises 283 11 Background Processing 284 Background Save 284 Background Processing 289 Introducing Faulter 290 Introducing Thumbnailer 294 Summary 300 Exercises 300 12 Search 302 Updating CoreDataTVC 303 Updating PrepareTVC 310 Summary 315 Exercises 315 13 Back Up and Restore with Dropbox 318 Dropbox Integration 319 Supporting Frameworks 320 Linking to Dropbox 321 Introducing DropboxHelper 323 Introducing DropboxTVC 325 Preparing CoreDataHelper 328 Building DropboxHelper 329 Local File Management 329 Dropbox File Management 331 Backup & Restore 333 Building DropboxTVC 337 Creating Backups 340 Displaying Backups 343 Restore 345 Summary 349 Exercises 349 14 iCloud 352 Overview 352 Enabling iCloud 354 Updating CoreDataHelper for iCloud 355 The iCloud Store 356 iCloud Notifications 358 The Debug Navigator 362 Disabling iCloud 363 Summary 369 Exercises 369 15 Taming iCloud 372 De-Duplication 372 Seeding 381 Developing with a Clean Slate 388 Configurations 390 Finishing Touches 391 Summary 392 Exercises 393 16 Web Service Integration 400 Introducing StackMob 400 The StackMob SDK 402 Creating a StackMob Application 403 Managed Object Model Preparation 404 Configuring a StackMob Client 406 Saving 408 Underlying Changes 410 Automatic Schema Generation 411 Schema Permissions 414 Authentication 415 Securing the User Class 417 Introducing LoginVC 418 Maintaining Responsiveness 427 Summary 429 Exercises 430 A: Preparing Grocery Dude for Chapter 1 432 New Xcode Project 432 Storyboard Design 433 App Icons and Launch Images 436 B: Preparing Grocery Cloud for Chapter 16 438 Renaming Grocery Dude 438 Repointing File Paths 439 Renaming Groups and Tests 440 Renaming the Scheme 441 Updating the Artwork 442 Disabling Camera and Image Support 442 Workaround: Section Name Key Path Issue 443 Summary 444 Index 446 A 446 B 447 C 448 D 456 E 458 F 458 G 458 H-K 459 L 460 M 465 N-O 466 P-Q 466 R 467 S 468 T 468 U 469 V 469 W 470 X-Z 470