Home > Store > Programming > Mac OS Programming
Core Data for iOS: Developing Data-Driven Applications for the iPad, iPhone, and iPod touch
- By Tim Isted, Tom Harrington
- Published May 24, 2011 by Addison-Wesley Professional. Part of the Core Frameworks Series series.
- Copyright 2011
- Dimensions: 7" x 9-1/8"
- Pages: 304
- Edition: 1st
- Book
- ISBN-10: 0-321-67042-6
- ISBN-13: 978-0-321-67042-7
Register your product to gain access to bonus material or receive a coupon.
Product Author Bios
Tim Isted has been writing software for Macintosh computers since 1995. He also builds web applications using Ruby on 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. He blogs on Core Data at www.timisted.net, and is currently co-organizing NSConference, a European conference for Mac developers.
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.
Source Code
Download the Source Code file.
|
23 of 24 people found the following review helpful
Amazon Verified Purchase(What's this?)
This review is from: Core Data for iOS: Developing Data-Driven Applications for the iPad, iPhone, and iPod touch (Paperback)
Note: I did receive the example code from the author of this book. He is working with the Publisher to get the code available on their website. Meantime he noted he is glad to make it available simply by emailing him a request.Got my copy yesterday and have been skimming through it. Recently started another book on the same topic by APress. Both appear to be good books but this one I have been waiting over a year for. I am not disappointed in the wait because the book is up to date on the latest iOS at the time of publishing. Just glancing through the book, I can tell it is written by two iOS veteran programmers who are there to guide the reader with best practices and a lot of things to watch out for. For example, there is a section describing various ways of storing binary large objects (BLOBS) and the authors present a handful of options and explain when each can be useful and what to watch out for with respect to memory management and future needs to adjust the... Read more
6 of 6 people found the following review helpful
Amazon Verified Purchase(What's this?)
This review is from: Core Data for iOS: Developing Data-Driven Applications for the iPad, iPhone, and iPod touch (Paperback)
I keep this by my desk when I'm coding for iOS. It's great for reference and every time I go to look something up I find a concrete answer. The sections on predicates is also very good and I reference it often. If you're brand new to Core Data on iOS, this is a great starting point, or if you're more experienced and are looking for a quick reference book, this book is for you.
4 of 4 people found the following review helpful
This review is from: Core Data for iOS: Developing Data-Driven Applications for the iPad, iPhone, and iPod touch (Paperback)
I just finished reading this book and loved it. Now, to set the tone of this review, I will say that I am an experienced software developer, and had a little experience with Core Data prior to getting the book. The book is not en entry-level book, nor should it be; Core Data is a complicated framework. The book assumes, as it must, that the reader knows something already about Cocoa development, Objective-C, and memory management. I think that's reasonable given the sophistication of the topic.I've read many technical books on varying topics in the iOS ecosystem, some good, some not so good. This book is excellent, in my opinion. The topic coverage is both broad and deep. The information is presented clearly and logically, and the examples are spot on and easy to grasp. What I think is more notable, however, is that this book is not just going to sit on my shelf now that I've read it. It is going to be a constant reference for me, which is, I think, what makes a good book... Read more |
› See all 10 customer reviews...
Online Sample Chapter
Core Data for iOS: A Core Data Primer
Sample Pages
Download the sample pages (includes Chapter 2 and Index)
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

This book includes free shipping!
This book includes free shipping!
eBook (Watermarked)
$31.99
$25.59
Includes EPUB, MOBI, and PDF
About eBook Formats
This eBook includes the following formats, accessible from your Account page after purchase:
EPUBThe open industry format known for its reflowable content and usability on supported mobile devices.
MOBIThe eBook format compatible with the Amazon Kindle and Amazon Kindle applications.
PDFThe popular standard, used most often with the free Adobe® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discretely watermarking it with your name, making it uniquely yours.
- Request an Instructor or Media review copy.
- Corporate, Academic, and Employee Purchases
- International Buying Options
Get access to thousands of books and training videos about technology, professional development and digital media from more than 40 leading publishers, including Addison-Wesley, Prentice Hall, Cisco Press, IBM Press, O'Reilly Media, Wrox, Apress, and many more. If you continue your subscription after your 30-day trial, you can receive 30% off a monthly subscription to the Safari Library for up to 12 months. That's a total savings of $199.

