You are previewing Pro iOS Persistence : Using Core Data.
O'Reilly logo
Pro iOS Persistence : Using Core Data

Book Description

Pro iOS Persistence explains how to build apps in Objective-C and Swift that persist and use data most effectively including the popular Core Data framework. Covering common and advanced persistence patterns, this book prepares any iOS developer to store and retrieve data accurately and efficiently.

This book starts by giving you a solid grounding in Core Data, providing a foundation for the rest of the book. With this knowledge, you'll have all you need to master Core Data and power your data-driven applications. You'll see how to work with SQLite and how to create an efficient data model to represent your data. Once you've established your data model, you'll learn how to work with data objects and refine result sets to get the most out of the stored data.

The advanced portions of the book begin by showing you how to tune your apps' performance and memory usage, to give you a truly professional edge. You'll see how to version and migrate your data as well, to ensure your data stays organized and efficient. Finally, the book covers managing table views with NSFetched Results Controller.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Authors
  8. About the Technical Reviewers
  9. Acknowledgments
  10. Introduction
  11. Chapter 1: Touring Core Data
    1. What Is Core Data?
    2. Core Data Components
    3. Creating a New Core Data Project
    4. Creating the Project
    5. Touring the Core Data Components
    6. Initializing the Core Data Components
    7. Creating a Managed Object Model
    8. Adding Some Objects
    9. Viewing the Data
    10. Adding Core Data to an Existing Project
      1. Creating a Core Data-less Application
      2. Adding the Core Data Framework
      3. Adding a Managed Object Model
      4. Adding and Initializing the Core Data Stack
      5. Creating the Object Model
      6. Adding Objects to PersistenceApp
    11. Wrapping Up
  12. Chapter 2: Building Data Models
    1. Designing Your Database
    2. Relational Database Normalization
    3. Building a Simple Model
      1. Entities
      2. Attribues
      3. Key-Value Coding
      4. Generating Classes
      5. Relationships
    4. Storing and Retrieving Data
      1. Inserting New Managed Objects
      2. Retrieving Managed Objects
      3. Predicates
      4. Fetched Properties
    5. Notifications
      1. Notification upon Creation
      2. Notification upon Fetch
      3. Notification upon Change
      4. Registering an Observer
      5. Receiving the Notifications
    6. Conclusion
  13. Chapter 3: Advanced Querying
    1. Building WordList
      1. Creating the Application
      2. Building the Data Model
      3. Creating the User Interface
      4. Loading and Analyzing the Word List
      5. Getting a Count
      6. Displaying the Statistics
    2. Querying Relationships
    3. Understanding Predicates and Expressions
      1. Viewing Your SQL Queries
      2. Creating Single-Value Expressions
      3. Creating Collection Expressions
      4. Comparing Expressions Using Different Predicate Types
      5. Using Different Comparison Modifiers
      6. Using Different Options
      7. Adding It Up: Using Compound Predicates
      8. Aggregating
      9. Using Subqueries
      10. Sorting
    4. Summary
  14. Chapter 4: Attending to Data Quality
    1. Seeding Data
      1. Using the Seed Store
      2. Updating Seeded Data in Subsequent Releases
    2. Undoing and Redoing
      1. Undo Groups
      2. Limiting the Undo Stack
      3. Disabling Undo Tracking
      4. Adding Undo to BookStore
      5. Experimenting with the Undo Groups
    3. Dealing with Errors
      1. Handling Core Data Operational Errors
      2. Handling Validation Errors
      3. Handling Validation Errors in BookStore
      4. Implementing the Validation Error-Handling Routine
      5. Summary
  15. Chapter 5: Integrating with the User Interface
    1. Displaying Table Data with NSFetchedResultController
      1. Creating a Fetched Results Controller
      2. Creating the Fetched Results Controller Delegate
    2. Storing Images
      1. Adding Screenshots to CoreDump
      2. Verifying the External Storage
    3. Searching the Fetched Results in the Table
      1. Adding the Search Controller
      2. Retrieving the Search Results
      3. Displaying the Search Results
    4. Conclusion
  16. Chapter 6: Versioning and Migrating Data
    1. Versioning
    2. Lightweight Migrations
      1. Migrating a Simple Change
      2. Renaming Entities and Properties
    3. Using a Mapping Model
      1. Understanding Entity Mappings
      2. Understanding Property Mappings
      3. Creating a New Model Version That Requires a Mapping Model
      4. Creating a Mapping Model
      5. Migrating Data
      6. Running Your Migration
    4. Custom Migrations
      1. Making Sure Migration Is Needed
      2. Setting Up the Migration Manager
      3. Running the Migration
    5. Summary
  17. Chapter 7: Transforming and Encrypting Data
    1. Using Transformable
      1. Creating the Project and Adding Core Data
      2. Creating Taps
      3. Creating the View and Displaying the Taps
      4. Hey, Wait a Minute! How Did My Color Transform?
    2. Encrypting Data
      1. Creating the Project and Setting Up the Core Data Model
      2. Performing the Encryption and Decryption
      3. Setting Up the Detail View to Edit a Note
      4. Prompting For and Verifying the Password
    3. An Alternative to Transformable: Data Protection
    4. Summary
  18. Chapter 8: Talking to Services: iCloud and Dropbox
    1. Integrating with iCloud
      1. Using iCloud’s Ubiquity Container
      2. Synching Content
    2. Integrating with Dropbox Datastore API
      1. Setting Up the API Access
      2. Creating a Blank App to Use with Dropbox
      3. Configuring the Callback URL
      4. Linking to Dropbox Using the Datastore API
      5. Creating and Synching Data with the Dropbox API
    3. Using Core Data with the Dropbox Datastore API: ParcelKit
      1. Adding the Required Frameworks for Dropbox and ParcelKit
      2. Integrating DropboxEvents with Dropbox
    4. Conclusion
  19. Chapter 9: Tuning Performance, Memory Usage, and Multithreading
    1. Tuning Performance
      1. Building the Application for Testing
      2. Running Your First Test
      3. Faulting
      4. Prefetching
      5. Caching
      6. Expiring the Cache
      7. Uniquing
      8. Improve Performance with Better Predicates
      9. Analyzing Performance
    2. Dealing with Multiple Threads
      1. Thread Safety
      2. Oh Come On, What Could Possibly Go Wrong?
      3. Gratuitous User Interface
      4. Initializing the Stack on a Different Thread
    3. Summary
  20. Index