Rough Cuts are manuscripts that are developed but not yet published, available through Safari. Rough Cuts provide you access to the very latest information on a given topic and offer you the opportunity to interact with the author to influence the final publication.
This is the Rough Cut version of the printed book.
Today, virtually every non-trivial iPhone and iPad app must manage data—quickly, smoothly, reliably, and with minimal impact on the CPU to conserve battery life. Core Data, Apple’s ready-made data persistence layer, can help you achieve all these goals. In Core Data for iOS, two leading iOS developers teach you the entire Core Data framework from the ground up. Writing for intermediate-to-advanced iOS developers, Tim Isted and Tom Harrington thoroughly explain how Core Data is used on iOS devices, introduce each of its primary classes, and show how they interact to provide amazing functionality with minimal configuration. You’ll learn how to store, fetch, and validate data; provide it efficiently to views; and much more. Isted and Harrington first give you a firm grounding in the technology, and then present real-world examples. They present multiple sample projects, as well as a start-to-finish, chapter-length case study. Coverage includes
• Understanding Core Data’s features, classes, and interactions
• Using Core Data in MVC-based iOS app development
• Mapping relational data to object models, and building them with Xcode 4’s Data Modeler
• Working with managed objects and using UITableView to display them
• Creating predicates to match numbers, data, and objects
• Maintaining compatibility across versions of an app’s data model
• Tracking managed object contexts across view controllers
• Using Core Data’s automatic Undo functionality
• Integrating abstract entities, entity inheritance, and multiple view controllers into a complete app
• Optimizing for iOS devices’ tight memory limits
• Diagnosing and fixing common Core Data problems
Introducing Addison-Wesley’s new Core Frameworks Series, written for experienced iOS developers by world-class Mac and iOS developers, these are the first comprehensive, code-rich reference guides to Apple’s Core Frameworks.
Preface ix
Part I Introduction
1 An Overview of Core Data on iOS Devices 3
A Little History 3
The Birth of Core Data 4
Why Use Core Data on iOS? 4
Relationship Management 4
Managed Objects and Data Validation 5
Undo and State Management 5
Core Data iOS and Desktop Differences 5
The Fetched Results Controller 6
Core Data Case Studies 6
MoneyWell for iPhone 6
Calcuccino 7
Associated Press 8
2 A Core Data Primer 9
Persisting Objects to Disk 9
The Core Data Approach 10
Entities and Managed Objects 10
Relationships 11
Managed Object Contexts 12
Fetching Objects 14
Faulting and Uniquing 14
Persistent Stores and Persistent Store Coordinators 15
Examining the Xcode Core Data Templates 15
The Navigation-Based Project Template 16
The Data Modeler 16
Setting up the Core Data Stack 17
Running the Application 20
A Quick Look at the RootViewController Code 20
Summary 21
3 Modeling Your Data 23
Managed Objects and Entities 23
Dividing Your Data into Entities 24
Core Data in Model-Object Terms 24
Data Normalization 25
Storing Binary Data 27
Working with Xcode’s Data Modeler 28
Creating Entities 29
Creating Properties 31
Creating Relationships 35
Summary 37
Part II Working with Core Data
4 Basic Storing and Fetching 41
Creating New Managed Objects 41
Saving the Context 42
Fetching Saved Managed Objects 44
Deleting Managed Objects 45
Working with Table Views 46
The Random Dates Application Project 47