O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Core Data iOS Essentials

Book Description

Knowing Core Data gives you the option of creating data-driven iOS apps, and this book is the perfect way to learn as it takes you through the process of creating an actual app with hands-on instructions.

  • Covers the essential skills you need for working with Core Data in your applications.
  • Particularly focused on developing fast, light weight data-driven iOS applications.
  • Builds a complete example application. Every technique is shown in context.
  • Completely practical with clear, step-by-step instructions.

In Detail

Core Data is the essential ingredient in data driven iOS apps. It's used for storing, retrieving, and manipulating application data in databases, XML, and binary formats. It's an essential component for iPhone, iPod Touch, and iPad apps.

Core Data Essentials provides a clear, readable guide to the most useful aspects of Core Data. Built around a realistic example app, the book showcases the most important aspects of Core Data development in the context of a complete, functioning app written in Objective C.

The book starts with a tour of how the app works. Then you'll see how to easily display data using the Table View. You'll learn how to develop an appropriate data model that fits the needs of your app, then implement that model as updatable data objects. You'll see how to update data and build relationships between objects and learn how Core Data can work with search, and how to provide your users with friendly data editing features.

Table of Contents

  1. Core Data iOS Essentials
    1. Table of Contents
    2. Core Data iOS Essentials
    3. Credits
    4. About the Author
    5. Acknowledgement
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    9. 1. Overview
      1. Prerequisite
      2. A brief history
        1. Enterprise Object Framework (EOF)
        2. Core Data
        3. Why use Xcode?
      3. Source code
      4. Shall we begin?
    10. 2. Understanding Core Data
      1. Core Data
        1. Core Data features
      2. Data Model
        1. Entities
        2. Properties
        3. Attributes
        4. Relationships
          1. Inverse relationship
      3. Model View Controller (MVC)
      4. Core Data API
        1. Persistent Store
        2. Persistent Store Coordinator
        3. FetchRequest
        4. FetchedResultsController
      5. Overview of the application: Sales Record System for a Departmental Store
      6. Entity Relationship Diagram
      7. An application output sample
        1. Entering Master Product Information
        2. Modifying the Master Product
        3. Deleting the Master Product
        4. Entering customer information and order details
        5. Deleting customer information
        6. Searching for specific customers
        7. Searching and modifying customer information
        8. Entering Customer Sales Information
      8. Automatic Master Product Update
      9. Summary
    11. 3. Understanding Objective-C Protocol and Table View
      1. Protocol
        1. Implementing the Strategy pattern
          1. Defining the protocol
          2. Creating a delegate property
          3. Declaring protocol methods
      2. Creating a sample application using a protocol and a delegate
        1. Adding the ViewController class for entering numerical values
        2. Defining the protocol, outlets, and action methods in the SecondViewController.h header file
        3. Defining the SecondViewController class and connecting controls
        4. Invoking delegate methods from the SecondViewController.m implementation file
        5. Declaring the delegate, outlet, and action methods in the demodelegateViewController.h header file
        6. Defining the demodelegateViewController and connecting controls
        7. Implementing the protocol methods in the demodelegateViewController.m file
        8. Running the project
      3. Introduction to Table View
      4. Creating an application to display Table View cells
        1. Declaring an array in the header file
        2. Implementing UITableViewDataSource protocol methods
      5. Adding names to the Table View
        1. Adding the AddNameController View controller
        2. Defining protocols, outlets, and action methods in the AddNameController.h header file
        3. Defining the AddNameController class View and connecting controls
        4. Invoking Delegate methods in the AddNameController.m implementation file
        5. Invoking the AddNameController View and implementing the protocol methods
        6. Placing and connecting the Bar Button Item control in the RootViewController
      6. Summary
    12. 4. Designing a Data Model and Building Data Objects for Customers
      1. Creating a new project
      2. Designing the data model
        1. Data Model Editor
        2. Adding an entity
        3. Adding an attribute property
          1. Types of attributes
          2. Fields applying constraints
      3. Building data objects for the Customer entity
      4. Understanding code of autogenerated files
        1. Header file of Application Delegate
        2. Implementation file of Application Delegate
          1. applicationWillTerminate method
          2. managedObjectContext method
          3. managedObjectModel method
          4. persistentStoreCoordinator method
          5. applicationDocumentsDirectory method
      5. Summary
    13. 5. Creating, Listing, and Deleting Names of Customers
      1. Splitting the task into two modules
      2. Creating a module to save and delete a customer's name
        1. Using the ViewController class for adding the name of the customer
        2. Defining protocol, outlets, and action methods in the header file
        3. Defining the View of the AddNameController class and connecting controls
        4. Invoking delegate methods from the implementation file
        5. Declaring delegate and implementing methods for storing the name of the customers
      3. Key value coding (KVC)
        1. Key value methods
          1. The -valueForKey: method
          2. The -setValue:forKey: method
          3. Keypath
      4. Implementing the methods of the NSFetchedResultsControllerDelegate protocol
        1. The controllerWillChangeContent method
        2. The controllerDidChangeContent method
        3. The controller:didChangeObject method
        4. The controller:didChangeSection method
      5. Running the project
      6. Summary
    14. 6. Creating, Listing, Displaying, and Deleting Records of Customers
      1. Understanding multiple managed object context
        1. NSNotification
      2. Applying the concept of multiple managed object context in our application
      3. Enhancing our application to save, list, display, and delete customer information
        1. Adding the ViewController class
        2. Defining a View for entering the customer's information and connecting controls
        3. Coding in the implementation file for accepting the customer's information and invoking delegate methods
        4. Adding the View Controller class for displaying the customer's information
        5. Defining the View and writing the code in the implementation file for displaying the customer's information
        6. Implementing the methods in the RootViewController class for storing the customer's information
      4. viewDidLoad method
      5. cell AtIndexPath method
      6. didSelectRowAtIndexPath method
      7. addCustomer method
      8. addcustomerController method
        1. Viewing the project
      9. Summary
    15. 7. Updating and Searching Records of Customers
      1. Applying the update feature
        1. Defining a protocol in the DisplayCustomerController class
        2. Adding Edit button to enable modifications in the View of DisplayCustomerController class
        3. Implementing the protocol's method for storing modified customer information
      2. Using KVO to know what has been updated
      3. Running the project
      4. Applying search facility
        1. Defining outlet of UISearchBar class in the header file of the RootViewController class
        2. Placing the Search Bar control in the View of RootViewController and specifying its delegate
        3. Implementing delegate method in the RootViewController class to apply searching
      5. Understanding NSPredicate
      6. Removing the keyboard after selecting a customer's name
      7. Using Predicate Builder for creating a search criterion
        1. Fetched properties
        2. Fetch request templates
          1. Building and accessing a fetch request without a variable
          2. Building and accessing a fetch request with a variable
      8. Summary
    16. 8. Entering, Saving, Listing, and Deleting the Records of the Products Sold to the Customers
      1. Adding the product entity to the Data Model
      2. Relationship
        1. Types of relationships
          1. One to one relationship
          2. One to many relationship
          3. Many to many relationship
      3. Establishing a relationship between the Customer and the Product entities
        1. Setting a relationship from the Customer entity to the Product entity
          1. Delete rule
        2. Setting a relationship from the Product entity to the Customer entity (inverse relationship)
      4. Building the data object for the Customer and the Product entities
        1. Understanding the role of the auto generated special methods of a relationship
      5. Entering the information of the products sold to the customers
      6. Creating a module to develop an interface to enter the product information
        1. Adding a ViewController class for entering the information of the products sold to the customers
        2. Defining the protocol, outlets, and action methods in the header file
        3. Designing the View of the AddProductController class and connecting the controls
        4. Invoking the delegate methods from the implementation file
      7. Developing a module to create a menu for manipulating the product information
        1. Adding a ViewController class to display the Product's menu to manipulate the product's information
        2. Defining the outlets and action methods in the header file
        3. Designing the View of a ProductInfoController class and connecting the controls
        4. Coding in the implementation file to save, edit, and display the product's information
      8. Creating a module to connect the Product's menu to the rest of the project
        1. Defining the outlets and action methods in the header file
        2. Adding a Toolbar control to the View of the DisplayCustomerController class
        3. Coding in the implementation file to invoke the View of the ProductInfoController class
      9. Running the project
      10. Summary
    17. 9. Entering, Displaying, and Deleting the Stock
      1. Adding the MasterProduct entity to the Data Model
      2. Storing the image of the MasterProduct
        1. Transformable data type
          1. The Value Transformer Name: field
          2. Creating a value transformer
      3. Building the data object for the MasterProduct entity
      4. Maintaining the MasterProduct information
        1. Image Picker
          1. Adding custom images to the Image Picker
        2. Making an image appear within a given size
        3. Module to develop interface to enter the information of the MasterProduct
          1. Adding the ViewController class for entering information of the master products
          2. Defining protocol, outlets, and action methods in the header file
          3. Designing the View of the MasterProductController class and connecting controls
          4. Invoking the delegate and ImagePicker methods from the implementation file
        4. Module to create a menu for manipulating the MasterProduct information
          1. Adding the View Controller class to display a menu for adding, editing, and displaying the MasterProducts
          2. Defining the outlets and action methods in the header file
          3. Designing the View of the MasterProductInfoController class and connecting controls
          4. Coding in the implementation file to save, edit, and display the master product's information
      5. Summary
    18. 10. Editing the Stock Information
      1. Module to connect the MasterProduct's menu to the rest of the project
        1. Defining outlets and action methods in the header file
        2. Adding a Toolbar and a Bar Button Item in the RootViewController class
        3. Coding in the implementation file to invoke the View of the MasterProductinfoController class
        4. Making the Toolbar to appear at the bottom of the View
      2. Running the application
        1. Selecting the image of the master product
        2. Deleting the master product
      3. Module to modify the information of the master product
        1. Adding the View Controller class to display the view to modify the selected master product
        2. Defining the outlets and action methods in the header file
        3. Designing the View of EditMasterProductController class
        4. Coding in the implementation file to modify the master product's information
        5. Importing the delegate and the View Controller class in the header file
        6. Coding in the implementation file to invoke the View of the EditMasterProductController class
      4. Summary
    19. 11. Displaying the Products for Sale and Updating the Stock
      1. Displaying the products available for sale
        1. Adding the SearchProductController class
        2. Designing the view of SearchProductController
        3. Coding in the SearchProductController class
        4. Invoking the SearchProductController from the Product menu
        5. Displaying name, price, and image of the selected product
      2. Updating the stock
        1. Running the project
      3. Automatically updating the quantity of the product in the MasterProduct entity
      4. Versioning
        1. Creating a new Data Model version
      5. Migrations
        1. Implementing lightweight migration to our application
      6. Summary
    20. A. Appendix
    21. Index