For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Download from Wow! eBook <www.wowebook.com>
iv
Contents at a Glance
Contents .............................................................................................................. v
About the Authors ............................................................................................... x
About the Technical Reviewer ........................................................................... xi
Acknowledgments ............................................................................................ xii
Introduction ..................................................................................................... xiii
■Chapter 1: Getting Started ............................................................................... 1
■Chapter 2: Understanding Core Data ............................................................. 27
■Chapter 3: Storing Data: SQLite and Other Options ....................................... 59
■Chapter 4: Creating a Data Model ................................................................ 111
■Chapter 5: Working with Data Objects ........................................................ 133
■Chapter 6: Refining Result Sets ................................................................... 187
■Chapter 7: Tuning Performance and Memory Usage ................................... 209
■Chapter 8: Versioning and Migrating Data .................................................. 253
■Chapter 9: Managing Table Views Using a Fetched Results Controller ....... 285
■Chapter 10: Using Core Data in Advanced Applications .............................. 307
Index ............................................................................................................... 367
xiii
Introduction
Interest in developing apps for Apple’s iOS platform continues to rise, and more great apps
appear in Apple’s App Store every day. As people like you join the app-creation party, they usually
discover that their apps must store data on iOS devices to be useful. Enter Pro Core Data for iOS,
written for developers who have learned the basics of iOS development and are ready to dive
deeper into topics surrounding data storage to take their apps from pretty good to great. Core
Data, Apple’s technology for data storage and retrieval, is both easy to approach and difficult to
master. This book spans the gamut, starting you with the simple and taking you through the
advanced. Read each topic, understand what it means, and incorporate it into your own Core
Data apps.
Why a Second Edition?
Since the publication of the first edition of Pro Core Data for iOS, Apple has released Xcode 4, a
major overhaul of their programming tool. Everything has moved or changed somehow, so the
descriptions and tutorials from the first edition of this book, which used Xcode 3, no longer apply.
All the descriptions and screenshots have been updated to the new interface.
We didn’t stop at updating the book for Xcode 4, however. We broke the discussion of
NSFetchedResultsController into its own chapter, giving it more treatment and coverage. We dug
deeper into the tricky topic of migrations. We took a new approach to the section on data
encryption, based on feedback from Brian Kohl. We responded to feedback we’ve received via
reviews and e-mail. We think both new readers and people who have already read the first edition
will profit from reading this edition.
What You’ll Need
To follow along with this book, you need an Intel Mac running Snow Leopard or Lion, and you
need Xcode 4, which is available from the Mac App Store or from developer.apple.com for
registered Apple developers. You’ll also do better if you have at least a basic understanding of
Objective-C, Cocoa Touch, and iOS development.
What You’ll Find
This book starts by setting a clear foundation for what Core Data is and how it works, and then it
takes you step-by-step through how to get the results you need from this powerful framework.
You’ll learn about the components of Core Data and how they interact, how to design your data
model, how to filter your results, how to tune performance, how to migrate your data across data
model versions, and many other topics around and between these that will separate your apps
from the crowd.
■ INTRODUCTION
xiv
This book combines theory and code to teach its subject matter. Although you can take the
book to your Barcalounger and read it from cover to cover, you’ll find the book is more effective if
you’re in front of a computer, typing in and understanding the code it explains. We also hope
that, after you read the book and work through its code, you’ll keep it handy as a reference,
turning to it often for answers and clarification.
How This Book Is Organized
We’ve tried to arrange the material so that it builds from beginning topics to advanced, at least in
a general sense, as the book progresses. The topics tend to build on each other, so you’ll likely
benefit most by working through the book front to back, rather than skipping around. If you’re
looking for guidance on a specific topic—versioning and migrating data, say, or tuning
performance and memory usage—skip ahead to that chapter. Most chapters focus on a single
topic, indicated by that chapter’s title. The final chapter covers an array of advanced topics that
don’t fit neatly anywhere else.
Source Code and Errata
You can and should download the source code for this book from the Apress web site at
www.apress.com. Feel free to use it in your own projects, whether personal or commercial. We’ll
post any corrections to code as they’re uncovered. We’ll also post book corrections in the errata
section.
How to Contact Us
We’d love to hear from you, whether it’s questions, concerns, better ways of doing things, or
triumphant announcements of your Core Data apps landing on the App Store. You can find us
here:
Michael Privat
E-mail: mprivat@mac.com
Twitter: @michaelprivat
Blog: http://michaelprivat.com
Rob Warner
E-mail: rwarner@grailbox.com
Twitter: @hoop33
Blog: http://grailbox.com