Pro Core Data for iOS: Data Access and Persistence Engine for iPhone, iPad, and iPod touch

Book description

Based on the relatively new Cocoa touch set of APIs and libraries, the Core Data framework is now available and accessible for app development and use on iPhone, iPad, and iPod touch devices. Pro Core Data for iOS explains how to use the Core Data framework for iOS.

The book explains both how and why to use Core Data, from simple to advanced techniques. Covering common and advanced persistence patterns, this book prepares any iOS developer to store and retrieve data accurately and efficiently.

  • Steps reader through Core Data

  • Graduates readers to advanced usage

  • Instructs how to tune and optimize persistence

Table of contents

  1. Copyright
  2. About the Authors
  3. About the Technical Reviewer
  4. Acknowledgments
  5. Introduction
    1. What to Expect from This Book
      1. What to Expect from This Book
    2. How This Book Is Organized
    3. Source Code and Errata
    4. How to Contact Us
  6. 1. Getting Started
    1. 1.1. What Is Core Data?
    2. 1.2. History of Persistence in iOS
    3. 1.3. Creating a Basic Core Data Application
      1. 1.3.1. Understanding the Core Data Components
      2. 1.3.2. Creating a New Project
      3. 1.3.3. Running Your New Project
      4. 1.3.4. Understanding the Application's Components
      5. 1.3.5. Fetching Results
      6. 1.3.6. Inserting New Objects
      7. 1.3.7. Initializing the Managed Context
    4. 1.4. Adding Core Data to an Existing Project
      1. 1.4.1. Adding the Core Data Framework
      2. 1.4.2. Creating the Data Model
      3. 1.4.3. Initializing the Managed Object Context
    5. 1.5. Summary
  7. 2. Understanding Core Data
    1. 2.1. Core Data Framework Classes
      1. 2.1.1. The Model Definition Classes
      2. 2.1.2. The Data Access Classes
      3. 2.1.3. Key-Value Observing
      4. 2.1.4. The Query Classes
    2. 2.2. How the Classes Interact
      1. 2.2.1. SQLite Primer
      2. 2.2.2. Reading the Data Using Core Data
    3. 2.3. Summary
  8. 3. Storing Data: SQLite and Other Options
    1. 3.1. Using SQLite as the Persistent Store
      1. 3.1.1. Configuring the One-to-Many Relationship
      2. 3.1.2. Building the User Interface
      3. 3.1.3. Configuring the Table
      4. 3.1.4. Creating a Team
      5. 3.1.5. The Player User Interface
      6. 3.1.6. Adding, Editing, and Deleting Players
      7. 3.1.7. Seeing the Data in the Persistent Store
    2. 3.2. Using an In-Memory Persistent Store
    3. 3.3. Creating Your Own Custom Persistent Store
      1. 3.3.1. Initializing the Custom Store
      2. 3.3.2. Mapping Between NSManagedObject and NSAtomicStoreCacheNode
      3. 3.3.3. Serializing the Data
      4. 3.3.4. Using the Custom Store
      5. 3.3.5. What About XML Persistent Stores?
    4. 3.4. Summary
  9. 4. Creating a Data Model
    1. 4.1. Designing Your Database
      1. 4.1.1. Relational Database Normalization
    2. 4.2. Using the Xcode Data Modeler
      1. 4.2.1. Viewing and Editing Attribute Details
      2. 4.2.2. Viewing and Editing Relationship Details
      3. 4.2.3. Using Fetched Properties
    3. 4.3. Creating Entities
    4. 4.4. Creating Attributes
    5. 4.5. Creating Relationships
      1. 4.5.1. Name
      2. 4.5.2. Optional
      3. 4.5.3. Transient
      4. 4.5.4. Destination and Inverse
      5. 4.5.5. To-Many Relationship
      6. 4.5.6. Min Count and Max Count
      7. 4.5.7. Delete Rule
    6. 4.6. Summary
  10. 5. Working with Data Objects
    1. 5.1. Understanding CRUD
      1. 5.1.1. Creating the Shape Application Data Model
      2. 5.1.2. Building the Shape Application User Interface
      3. 5.1.3. Enabling User Interactions with the Shapes Application
    2. 5.2. Generating Classes
    3. 5.3. Modifying Generated Classes
    4. 5.4. Using the Transformable Type
    5. 5.5. Validating Data
      1. 5.5.1. Custom Validation
      2. 5.5.2. Invoking Validation
      3. 5.5.3. Default Values
    6. 5.6. Undoing and Redoing
      1. 5.6.1. Undo Groups
      2. 5.6.2. Limiting the Undo Stack
      3. 5.6.3. Disabling Undo Tracking
      4. 5.6.4. Adding Undo to Shapes
    7. 5.7. Summary
  11. 6. Refining Result Sets
    1. 6.1. Building the Test Application
      1. 6.1.1. Creating the Org Chart Data
      2. 6.1.2. Reading and Outputting the Data
    2. 6.2. Filtering
      1. 6.2.1. Expressions for a Single Value
      2. 6.2.2. Expressions for a Collection
      3. 6.2.3. Comparison Predicates
      4. 6.2.4. Compound Predicates
      5. 6.2.5. Subqueries
    3. 6.3. Aggregating
    4. 6.4. Sorting
      1. 6.4.1. Returning Unsorted Data
      2. 6.4.2. Sorting Data on One Criterion
      3. 6.4.3. Sorting on Multiple Criteria
    5. 6.5. Summary
  12. 7. Tuning Performance and Memory Usage
    1. 7.1. Building the Application for Testing
      1. 7.1.1. Creating the Core Data Project
      2. 7.1.2. Creating the Data Model and Data
      3. 7.1.3. Creating the Testing View
      4. 7.1.4. Building the Testing Framework
      5. 7.1.5. Adding the Testing Framework to the Application
      6. 7.1.6. Running Your First Test
    2. 7.2. Faulting
      1. 7.2.1. Firing Faults
      2. 7.2.2. Faulting and Caching
      3. 7.2.3. Refaulting
      4. 7.2.4. Building the Faulting Test
      5. 7.2.5. Taking Control: Firing Faults on Purpose
      6. 7.2.6. Prefetching
    3. 7.3. Caching
    4. 7.4. Expiring
      1. 7.4.1. Memory Consumption
      2. 7.4.2. Brute-Force Cache Expiration
      3. 7.4.3. Expiring the Cache Through Faulting
    5. 7.5. Uniquing
    6. 7.6. Improve Performance with Better Predicates
      1. 7.6.1. Using Faster Comparators
      2. 7.6.2. Using Subqueries
    7. 7.7. Analyzing Performance
      1. 7.7.1. Launching Instruments
      2. 7.7.2. Understanding the Results
    8. 7.8. Summary
  13. 8. Versioning and Migrating Data
    1. 8.1. Versioning
      1. 8.1.1. Switching from Unversioned to Versioned
    2. 8.2. Lightweight Migrations
      1. 8.2.1. Migrating a Simple Change
      2. 8.2.2. Migrating More Complex Changes
      3. 8.2.3. Renaming Entities and Properties
    3. 8.3. Creating a Mapping Model
      1. 8.3.1. Understanding Entity Mappings
      2. 8.3.2. Understanding Property Mappings
      3. 8.3.3. Creating a New Model Version That Requires a Mapping Model
      4. 8.3.4. Creating a Mapping Model
    4. 8.4. Migrating Data
      1. 8.4.1. Running Your Migration
    5. 8.5. Custom Migrations
      1. 8.5.1. Making Sure Migration Is Needed
      2. 8.5.2. Setting Up the Migration Manager
      3. 8.5.3. Running the Migration
    6. 8.6. Summary
  14. 9. Using Core Data in Advanced Applications
    1. 9.1. Creating an Application for Note and Password Storage and Encryption
      1. 9.1.1. Setting Up the Data Model
      2. 9.1.2. Setting Up the Tab Bar Controller
      3. 9.1.3. Adding the Tab
    2. 9.2. Managing Table Views Using NSFetchedResultsController
      1. 9.2.1. Understanding NSFetchedResultsController
        1. 9.2.1.1. The Fetch Request
        2. 9.2.1.2. The Managed Object Context
        3. 9.2.1.3. The Section Name Key Path
        4. 9.2.1.4. The Cache Name
      2. 9.2.2. Understanding NSFetchedResultsController Delegates
      3. 9.2.3. Using NSFetchedResultsController
      4. 9.2.4. Incorporating NSFetchedResultsController into MyStash
        1. 9.2.4.1. Creating the Fetched Results Controller
        2. 9.2.4.2. Implementing the NSFetchedResultsControllerDelegate Protocol
        3. 9.2.4.3. Incorporating the Fetched Results Controllers into the Tables
      5. 9.2.5. Creating the Interface for Adding and Editing Notes and Passwords
    3. 9.3. Splitting Data Across Multiple Persistent Stores
      1. 9.3.1. Using Model Configurations
    4. 9.4. Adding Encryption
      1. 9.4.1. Persistent Store Encryption Using Data Protection
      2. 9.4.2. Data Encryption
        1. 9.4.2.1. Using Encryption
        2. 9.4.2.2. Automatically Encrypting Fields
        3. 9.4.2.3. Changing the User Interface to Use the text Attribute
        4. 9.4.2.4. Testing the Encryption
    5. 9.5. Sending Notifications When Data Changes
      1. 9.5.1. Registering an Observer
      2. 9.5.2. Receiving the Notifications
    6. 9.6. Seeding Data
      1. 9.6.1. Adding Categories to Passwords
      2. 9.6.2. Creating a New Version of Seeded Data
    7. 9.7. Error Handling
      1. 9.7.1. Handling Core Data Operational Errors
      2. 9.7.2. Handling Validation Errors
      3. 9.7.3. Handling Validation Errors in MyStash
        1. 9.7.3.1. Implementing the Validation Error Handling Routine
    8. 9.8. Summary

Product information

  • Title: Pro Core Data for iOS: Data Access and Persistence Engine for iPhone, iPad, and iPod touch
  • Author(s):
  • Release date: January 2011
  • Publisher(s): Apress
  • ISBN: 9781430233558