Core Data for iOS: Developing Data-Driven Applications for the iPad, iPhone, and iPod touch

( 1 )


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 ...

See more details below
Paperback (Original)
$30.94 price
(Save 22%)$39.99 List Price
Other sellers (Paperback)
  • All (12) from $1.99   
  • New (5) from $23.01   
  • Used (7) from $1.99   
Core Data for iOS: Developing Data-Driven Applications for the iPad, iPhone, and iPod touch

Available on NOOK devices and apps  
  • NOOK Devices
  • Samsung Galaxy Tab 4 NOOK 7.0
  • Samsung Galaxy Tab 4 NOOK 10.1
  • NOOK HD Tablet
  • NOOK HD+ Tablet
  • NOOK eReaders
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac

Want a NOOK? Explore Now

NOOK Book (eBook)
$17.99 price
(Save 43%)$31.99 List Price


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.

Read More Show Less

Product Details

  • ISBN-13: 9780321670427
  • Publisher: Addison-Wesley
  • Publication date: 6/7/2011
  • Series: Core Frameworks Series
  • Edition description: Original
  • Edition number: 1
  • Pages: 304
  • Sales rank: 586,799
  • Product dimensions: 8.92 (w) x 7.04 (h) x 0.65 (d)

Meet the Author

Tim Isted has been writing software for Macintosh computers since 1995. He also builds web applications using Rails, PHP, and .NET and has been known to develop for Windows machines too. Also a professional musician and singing teacher, he tries to divide his time fairly equally between conducting, accompanying, teaching, and writing software. Previous musings on Core Data for desktop development can be found on his blog at, and he is also co-organizer of NSConference, a new Mac developer conference taking place in both Europe and the USA.

Tom Harrington switched from writing software for embedded systems and Linux to Mac OS X in 2002 when he started Atomic Bird, LLC. After six years of developing highly regarded Mac software he moved to iPhone in 2008. He develops iOS software on a contract basis for a variety of clients. Tom also organizes iOS developer events in Colorado. When not writing software he can often be found on his mountain bike. His website is

Read More Show Less

Table of Contents

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

The Random Dates Data Model 48

Basic RootViewController Behavior 49

Fetching the Random Date Objects 51

Displaying the RandomDate Objects 52

Deleting the RandomDate Objects 54

Custom Managed Object Sub-Classes 54

Creating and Setting a Custom Class for a Managed Object 56

Summary 60

5 Using NSFetchedResultsController 61

Introducing NSFetchedResultsController 62

Creating an NSFetchedResultsController 62

Supplying Information to Table Views 64

The Number of Sections and Rows 65

Returning the Cell for an Index Path 67

Returning Information about Sections 68

Handling Underlying Data Changes 69

Caching Information 72

Using an NSFetchedResultsController in the Random Dates Application 73

Subclassing NSFetchedResultsController 80

Summary 85

6 Working with Managed Objects 87

Basic Managed Object Subclass Files 87

Creating the Random People Project 88

Managed Object Class Interfaces 89

Managed Object Class Implementations 90

Configuring the Random People Application 93

Displaying the Information 95

Data Validation 99

Validating Individual Properties 99

Validation Based on Other Properties 101

Validation Prior to Deletion 104

Fixing the Random People Application 105

Working with Transient Attributes 105

Modifying the Data Model 106

Adding to the AWPerson Interface and Implementation 106

Adding a Getter Method for the Transient Property 108

Adding a Setter Method for the Transient Property 110

Using the UIColor Property 111

Working with Transformable Attributes 113

The Managed Object Lifecycle 114

Initializing Non-persistent Properties 114

Summary 116

7 Working with Predicates 117

Predicate Basics 117

Creating Predicates Using Format Strings 118

Predicate Variables 120

Predicate Comparison Operators 122

Key Paths 123

Comparing Strings 124

Compound Predicates 126

NSCompoundPredicate 128

Sets and Relationships 129

Examining SQL Queries 130

Adding a Search Display Controller 130

Setting a Fetch Predicate 132

Modifying the Search Predicate 136

Adding a Search Scope Bar Filter 139

Summary 141

8 Migration and Versioning 143

The Migration Problem 143

Changing the Data Model 144

Multiple Data Model Versions and Lightweight Migration 145

Creating Data Model Versions 145

Enabling Lightweight Migration 146

Renaming Entities and Attributes 148

Supplying Renaming Identifiers 150

Keeping Track of Multiple Versions 151

Mapping Models 152

Custom Entity Migration Policies 156

Summary 160

9 Working with Multiple View Controllers and Undo 163

Editing Managed Objects 163

Keeping Track of the Managed Object to Edit 164

Updating a Managed Object’s Properties 168

Validating Managed Objects 171

Working with Undo 174

Multiple Managed Object Contexts 175

Merging Changes from Other Managed Object Contexts 178

Changing Managed Object Values Whenever the Control Values

Change 179

Resetting a Managed Object Context 181

Using the Editor Controller to Add New Objects 182

Summary 183

Part III Building a Simple Core Data Application

10 Sample Application: Note Collector 187

The Note Collector Application 187

Creating the Note Collector Project 188

The Application Data Model 188

Modeling an Abstract Entity 189

Modeling Sub-entities 189

Creating Managed Object Class Files 190

Configuring the RootViewController 192

Displaying the Contents of a Collection 195

Keeping Track of the Collection to be Displayed 196

Examining the Contents of a Raw Data File 200

Setting and Editing an Item Name 202

Creating the New View Controller 203

Displaying and Editing Notes 210

Supplying a Pre-Populated Data Store 217

Working with a Data Store in the Application Bundle 217

Summary 219

Part IV Optimizing and Troubleshooting

11 Optimizing for iOS Performance and Memory Requirements 223

Performance, Optimization, and Speed 224

Data Store Types 224

Binary and Memory Data Stores 225

SQLite Data Store 225

Monitoring SQLite Stores 225

Optimizing Fetching 230

Setting Fetch Limits 230

Optimizing Predicates 231

Pre-Fetching Relationships 233

Pre-Fetching Any Object 234

Pre-Loading Property Values 235

NSFetchedResultsController and Sections 235

Managing Faulting 235

“Safe” Fault-Free Methods 236

Preventing Property Loading 237

Batch Faulting 237

Re-faulting Objects 237

Managing BLOBs 238

Putting BLOBs in the Entity That Uses Them 239

Putting BLOBs in a Separate Entity 240

Putting BLOBs in External Files 242

Monitoring Core Data with Instruments 245

When Not to Use Core Data 248

Other Memory Management Tips 248

Don’t Use an Undo Manager If You Don’t Need It 249

Resetting the Managed Object Context 249

Summary 249

12 Troubleshooting Core Data 251

Your First Core Data Error 251

The Missing Model 254

Classes Not Found? 255

Core Data Threading Issues 257

Basics of Core Data Multithreading 257

Coordinating Data Between Threads 258

When Threads Collide, or Handling Data Conflicts 260

Danger! Temporary ID! 264

Problems Using Managed Objects 265

Crashing When Setting Property Values 265

If Custom Accessor Methods Aren’t Called 266

Managed Object Invalidated 267

Faults That Can’t Be Fulfilled 268

Problems Fetching Objects 269

Trouble Sorting Data During Fetches 269

Fetch Results Not Showing Recent Changes 270

Summary 270

Index 271

Read More Show Less

Customer Reviews

Average Rating 5
( 1 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Posted November 27, 2011

    Great resource from those taking the next step in Core Data development

    This is now my "go-to" text on Core Data. Nicely organized with enough detail to help you move on to design and build your own core data apps. It's wrapped up with a chapter on building a more complete app. Especially helpful is the chapter on troubleshooting tips.

    I have the Nook version and find it well-formatted for my iPad and computer screens. Much better than earlier programming texts in the eBook formats.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)