Core Data is Apple’s recommended way to persist data: it’s easy to use, built-in, and integrated with iCloud. It’s intricate, powerful, and necessary—and this book is your guide to harnessing its power.

Learn fundamental Core Data principles such as thread and memory management, discover how to use Core Data in your iPhone, iPad, and OS X projects by using NSPredicate to filter data, and see how to add iCloud to your applications.

Buy Now

Select a DRM-free Format:

In Stock
In Stock
In Stock
Buy the eBook and get these DRM-free formats delivered immediately:
  • epub (for iPhone/iPad, Android, eReaders)
  • mobi (for Kindle)
  • PDF
We can automatically send them to your Kindle, and your Dropbox. (You'll need to log in to enable these options.)
 

About this Book

  • 256 pages
  • Published:
  • Release: P2.0 (2014-03-28)
  • ISBN: 978-1-93778-508-6

Cocoa expert Marcus Zarra walks you through developing a full-featured application based around the Core Data APIs. You’ll build up a single application throughout the book, learning key Core Data principles such as NSPredicate, thread management, and memory management.

Geared toward intermediate to advanced developers, this book gets you comfortable with the basics of Core Data. Then you’ll delve deep into the details of the API. You’ll explore not only how to get Core Data integrated into your application properly, but even better, how to work with the API’s flexibility to create convenience methods to improve your application’s maintainability. Learn how to reduce your number of mapping models, integrate your Core Data app with Spotlight and Quick Look, connect your application with sync services, and find out how to use Core Data in a multithreaded environment. By the end of the book, you’ll have built a full-featured application, gained a complete understanding of Core Data, and learned how to integrate your application into the iPhone/iPad platform.

This second edition updates all examples for OS X Mountain Lion and iOS 6, gets you up to speed on changes in multithreading, and provides new chapters covering iCloud and NSFetchedResultsController.


Q&A with Core Data, 2nd edition author Marcus Zarra

Why is Core Data important? Why do developers need to know it?

Core Data is Apple’s recommended model management and persistence framework.  By learning and using Core Data, you can save yourself a significant amount of development time on every application you build.  In some cases, you can save as much as 30 percent of the application development time by using Core Data.

How has Core Data changed since the first edition of this book?

Starting with iOS 5.0 and Mac OS X 10.7, the majority of Core Data has remained remarkably consistent since the first release of this book. It has become even more friendly with threading. In addition, the framework has solved a few difficult issues that existed since its inception. However, our understanding of Core Data on iOS has grown significantly since its initial release. That increased understanding is included in this book.

What’s new in this edition?

Significant portions of the book have been rewritten with a new focus primarily on iOS, and secondarily on OS X.  Since iOS has all of the features that are available on OS X, you can learn the entirety of Core Data through iOS.  The portions of the book that focus solely on iOS are clearly marked.

What kind of background do readers need to get the most out of this book?

A reader interested in this book should be familiar with Objective-C and Cocoa. The book assumes you have a basic working knowledge of Objective-C and have developed one or more iOS/Mac OS X applications. It cannot be stressed enough that this book is written for developers at an intermediate level and could be quite difficult for a beginner to consume.

What kind of application do you build in this book, and what does Core Data add to it?

From the beginning of the book, we will develop a recipe iOS application and then refine it as our knowledge and understanding grows.  Core Data is an integral part of the application that we develop and handles the management of the data structures as well as the persistence of the data.  Without Core Data, we would need to write a significant amount of code to replace it.

What should readers expect to take away from the book?

A solid understanding of Core Data and how to use it in both future and existing applications.  Once you become comfortable with Core Data, you won’t want to use any other persistence framework.

What You Need

Mac OS X Mountain Lion and iOS 6. This book is for intermediate-level iOS developers.

Contents and Extracts

  • Introduction
  • Under the Hood of Core Data
  • iOS: NSFetchedResultsController
  • Versioning and Migration
    • Some Maintenance Before We Migrate
    • A Simple Migration
    • The Difference Between Light and Heavy Migrations
    • A Heavy/Manual Migration
    • Fundamentals of Core Data Versioning
    • Progressive Data Migration (An Academic Exercise)
  • Performance Tuning
    • Persistent Store Types
    • Optimizing Your Data Model excerpt
    • Fetching
    • Faulting
    • Access Patterns
  • Threading
    • Why Isn’t Core Data Thread-Safe?
    • Creating Multiple Contexts
    • Exporting Recipes
    • Importing Recipes
    • Parent/Child NSManagedObjectContext Instances excerpt
    • Wrap Up
  • Using iCloud
    • Introducing the UIManagedDocument excerpt
    • Direct NSManagedObjectContext to iCloud
    • Consuming Changes from iCloud
    • Under the Hood
    • Migrating an Existing Application
    • Desktop iCloud Integration
    • Data Quantities
    • Sharing Data between iOS and OS X
  • Adding a Desktop Foundation
    • Our Application
    • Our Application Design
    • Sharing the Data Model
    • Building the Controller Layer
    • Building the User Interface
    • Adding a Splash of Code
  • OS X: Bindings, KVC, and KVO
    • Key Value Coding
    • Key Value Observing
    • Cocoa Bindings and Core Data
    • Other Interface Elements That Use KVO, KVC, and Core Data
    • Coming Up
  • Spotlight, Quick Look, and Core Data
    • Integrating with Spotlight
    • Integrating with Quick Look
    • Putting It All Together
    • Taking It Further
  • Dynamic Parameters
    • Building the Xcode Example Project
    • The DocumentPreferences Object
    • Review
  • Distributed Core Data
    • Building the Server
    • Building the Client
    • Testing the Networking Code
    • Wrapping Up
  • Building a Foundation
    • The Storyboard
    • The Recipe List
    • The Recipe Detail
    • The Edit Workflow
    • Ready for Core Data
  • Macros in the Pre-compiled Header
    • Where Are the Macros?
    • What Do They Do?

About the Author

Marcus S. Zarra is co-owner of Empirical Development, LLC. A software developer since 1985, he has spoken at numerous conferences around the globe and taught Objective-C at top U.S. colleges. He is known as the single most experienced developer of Core Data applications outside of Apple. He blogs about development on Cocoa Is My Girlfriend.

Comments and Reviews

  • I learned Core Data reading the first edition of this book. It has long been my go-to reference, but a lot has changed since the first edition hit the shelves. The coverage of iOS and iCloud is a welcome addition, and the updated chapters on versioning and threading are a must-read. Those getting started with Core Data and those already using it owe it to themselves to read this fantastic book.

    —Kirby Turner, Chief Code Monkey White Peak Software, Inc.
  • If you need to know Core Data inside and out, you need this book. Marcus not only communicates what you need to know but has deep experience in making Core Data applications. That experience shines through in every chapter and example.

    —Bill Dudney, Gala Factory Software, LLC
  • This book has information for beginners and experts alike, particularly around new features such as iCloud syncing. It’s a must-have if you’re going to be doing anything with Core Data.

    —Patrick Burleson, Owner BitBQ, LLC
  • If you’re using Core Data and haven’t read this book, you’re doing yourself and your customers a disservice. Marcus Zarra explains the fundamental components of the Core Data framework and shows how the framework is used in real-world programming. This book is a must-read for anyone new to Core Data, but there’s plenty of great information even for seasoned veterans.

    —Jeff LaMarche, Author and Co-Founder MartianCraft, LLC