Learning Core Data for iOS: A Hands-On Guide to Building Core Data Applications

Book description

Get Started Fast with iOS 7 Core Data App Development
Covers iOS 7 and Xcode 5

This is the first Core Data book to fully reflect Apple’s latest platform innovations, including its dramatic¿ recent improvements to iCloud support. Hands-on from start to finish, it teaches you step-by-step as you create a modern data-driven iOS app using Storyboards, ARC, iOS 7, and Xcode 5.

Tim Roadley introduces new patterns and best practices designed to overcome the frustrations of Core Data development. One step at a time, you’ll build and extend your skills--even mastering advanced techniques such as complex model migration, deep copy, background processing, and integration with Dropbox, StackMob, and iCloud.

Downloadable versions of this book’s main project are provided with each chapter, so you can see exactly what your app project should look like--and get cookbook-style code for your own projects. Chapter exercises help you explore even further, whether you’re a self-learner or a student in an iOS development course.

If you’re an experienced iOS developer, this guide brings together all the skills, tools, code, and patterns you need to add powerful data management capabilities to any app--quickly, easily, and painlessly.

Coverage includes the following:

  • Understanding Core Data

  • Adding Core Data to an existing project

  • Designing, upgrading, and migrating data models (automatically and manually with progress indication)

  • Populating views with data, including table-views and picker-views

  • Preloading a “default data” persistent store from XML

  • Deep-copying from one persistent store to another

  • Performance tuning with Instruments, using large photos as the example

  • Background processing, using thumbnail generation as the example

  • Efficient search

  • Seamlessly backing up and restoring with Dropbox

  • Stable integration with iCloud--with full support for multiple accounts, seeding, and de-duplication

  • Web service integration with StackMob

  • Table of contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Dedication Page
    5. Contents at a Glance
    6. Table of Contents
    7. Acknowledgments
    8. About the Author
    9. Preface
      1. Who Is This Book For?
      2. What You’ll Need
      3. How This Book Is Organized
      4. Getting the Sample Code
    10. Editor’s Note: We Want to Hear from You!
    11. 1. Your First Core Data Application
      1. What Is Core Data?
        1. Persistent Store Coordinator
        2. Managed Object Model
        3. Managed Object Context
      2. When to Use Core Data
      3. Introducing Grocery Dude
      4. Adding Core Data to an Existing Application
        1. Introducing Core Data Helper
        2. Core Data Helper Implementation
        3. Files
        4. Paths
        5. Setup
        6. Saving
      5. Summary
      6. Exercises
    12. 2. Managed Object Model Basics
      1. What Is a Managed Object Model?
      2. Adding a Managed Object Model
      3. Entities
      4. Attributes
      5. Integer 16/32/64
      6. Float and Double
        1. Decimal
        2. String
        3. Boolean
        4. Date
        5. Binary Data
        6. Transformable
      7. Attribute Settings
      8. Subclassing NSManagedObject
      9. Scalar Properties for Primitive Data Types
      10. Snippet Demo Method
      11. Creating a Managed Object
      12. Backend SQL Visibility
      13. Fetching Managed Objects
        1. Fetch Request Sorting
        2. Fetch Request Filtering
        3. Fetch Request Templates
      14. Deleting Managed Objects
      15. Summary
      16. Exercises
    13. 3. Managed Object Model Migration
      1. Changing a Managed Object Model
      2. Adding a Model Version
      3. Lightweight Migration
      4. Default Migration
      5. Migration Manager
      6. Summary
      7. Exercises
    14. 4. Managed Object Model Expansion
      1. Relationships
      2. Delete Rules
      3. Validation Errors
      4. Entity Inheritance
      5. Summary
      6. Exercises
    15. 5. Table Views
      1. Table Views 101
      2. Core Data Table Views
      3. Introducing CoreDataTVC
        1. Fetching
        2. DATASOURCE: UITableView
      4. DELEGATE: NSFetchedResultsController
      5. AppDelegate’s CoreDataHelper Instance
      6. Introducing PrepareTVC
        1. Data
        2. View
        3. Interaction
      7. Introducing ShopTVC
        1. Data
        2. View
        3. Interaction
      8. Summary
      9. Exercises
    16. 6. Views
      1. Overview
      2. The Target View Hierarchy
      3. Introducing ItemVC
        1. Keeping Reference to a Selected Item
        2. Passing a Selected Item to ItemVC
        3. Configuring the Scroll View and Text Fields
        4. ItemVC Implementation
        5. Interaction
      4. DELEGATE: UITextField
        1. View
        2. Data
      5. Units, Home Locations, and Shop Locations
        1. Adding and Editing Units
        2. Implementing UnitsTVC
        3. Implementing UnitVC
        4. Segue from UnitsTVC to UnitVC
        5. Adding and Editing Home or Shop Locations
        6. Configuring the Home Location Views
        7. Configuring the Shop Location Views
      6. Summary
      7. Exercises
    17. 7. Picker Views
      1. Overview
      2. Introducing CoreDataPickerTF
      3. DELEGATE+DATASOURCE: UIPickerView
        1. Interaction
        2. Data
        3. View
      4. Introducing UnitPickerTF
        1. Creating the Unit Picker
        2. Connecting the Unit Picker
        3. Configuring ItemVC for the Unit Picker
      5. Introducing LocationAtHomePickerTF
      6. Introducing LocationAtShopPickerTF
        1. Creating the Location Pickers
        2. Connecting the Location Pickers
        3. Configuring ItemVC for the Location Pickers
      7. Picker-Avoiding Text Field
      8. Summary
      9. Exercises
    18. 8. Preloading Data
      1. Default Data
      2. Is an Import Required?
      3. Importing from XML
      4. Creating an Import Context
      5. Preventing Duplicate Default Data
      6. Triggering a Default Data Import
      7. Introducing CoreDataImporter
      8. Selecting Unique Attributes
      9. Mapping XML Data to Entity Attributes
      10. Importing from a Persistent Store
        1. Using the Default Data Store as the Initial Store
      11. Summary
      12. Exercises
    19. 9. Deep Copy
      1. Overview
      2. Configuring a Source Stack
        1. Configuring the Source Store
      3. Enhancing CoreDataImporter
        1. Object Info
        2. Array For Entity
        3. Copy Unique Object
        4. Establish To-One Relationship
        5. Establish To-Many Relationship
        6. Establish Ordered To-Many Relationship
        7. Copy Relationships
        8. Deep Copy Entities
      4. Triggering a Deep Copy
      5. Summary
      6. Exercises
    20. 10. Performance
      1. Identifying Performance Issues
      2. Implementing the Camera
      3. Generating Test Data
      4. Measuring Performance with SQLDebug
      5. Measuring Performance with Instruments
      6. Improving Performance
      7. Clean Up
      8. Summary
      9. Exercises
    21. 11. Background Processing
      1. Background Save
      2. Background Processing
      3. Introducing Faulter
      4. Introducing Thumbnailer
      5. Summary
      6. Exercises
    22. 12. Search
      1. Updating CoreDataTVC
      2. Updating PrepareTVC
      3. Summary
      4. Exercises
    23. 13. Back Up and Restore with Dropbox
      1. Dropbox Integration
        1. Supporting Frameworks
        2. Linking to Dropbox
        3. Introducing DropboxHelper
        4. Introducing DropboxTVC
      2. Preparing CoreDataHelper
      3. Building DropboxHelper
        1. Local File Management
        2. Dropbox File Management
        3. Backup & Restore
      4. Building DropboxTVC
        1. Creating Backups
        2. Displaying Backups
        3. Restore
      5. Summary
      6. Exercises
    24. 14. iCloud
      1. Overview
      2. Enabling iCloud
      3. Updating CoreDataHelper for iCloud
        1. The iCloud Store
        2. iCloud Notifications
      4. The Debug Navigator
      5. Disabling iCloud
      6. Summary
      7. Exercises
    25. 15. Taming iCloud
      1. De-Duplication
      2. Seeding
      3. Developing with a Clean Slate
      4. Configurations
      5. Finishing Touches
      6. Summary
      7. Exercises
    26. 16. Web Service Integration
      1. Introducing StackMob
      2. The StackMob SDK
      3. Creating a StackMob Application
      4. Managed Object Model Preparation
      5. Configuring a StackMob Client
      6. Saving
      7. Underlying Changes
      8. Automatic Schema Generation
      9. Schema Permissions
      10. Authentication
        1. Securing the User Class
        2. Introducing LoginVC
      11. Maintaining Responsiveness
      12. Summary
      13. Exercises
    27. A. Preparing Grocery Dude for Chapter 1
      1. New Xcode Project
      2. Storyboard Design
      3. App Icons and Launch Images
    28. B. Preparing Grocery Cloud for Chapter 16
      1. Renaming Grocery Dude
      2. Repointing File Paths
      3. Renaming Groups and Tests
      4. Renaming the Scheme
      5. Updating the Artwork
      6. Disabling Camera and Image Support
      7. Workaround: Section Name Key Path Issue
      8. Summary
    29. Index

    Product information

    • Title: Learning Core Data for iOS: A Hands-On Guide to Building Core Data Applications
    • Author(s): Tim Roadley
    • Release date: November 2013
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780133373585