You are previewing Professional iPhone® and iPad™ Database Application Programming.
O'Reilly logo
Professional iPhone® and iPad™ Database Application Programming

Book Description

A much-needed resource on database development and enterprise integration for the iPhone

An enormous demand exists for getting iPhone applications into the enterprise and this book guides you through all the necessary steps for integrating an iPhone app within an existing enterprise. Experienced iPhone developers will learn how to take advantage of the built-in capabilities of the iPhone to confidently implement a data-driven application for the iPhone.

Coverage includes:

  • Introducing Data-Driven Applications

  • The iPhone and iPad Database: Sqlite

  • Displaying Your Data: The UITableView

  • ipad Interface Elements

  • Introducing Core Data

  • Modeling Data in Xcode

  • Building a Core Data Application

  • Core Data-Related Cocoa Features

  • Core Data Migration and Performance

  • Working with Xml on the iPhone

  • Integrating with Web Services

Professional iPhone and iPad Database Application Programming gets you up to speed on developing data-driven applications for the iPhone.

Table of Contents

  1. Copyright
  2. CREDITS
  3. ABOUT THE AUTHOR
  4. ABOUT THE TECHNICAL EDITOR
  5. ACKNOWLEDGMENTS
  6. INTRODUCTION
    1. WHO THIS BOOK IS FOR
    2. WHAT THIS BOOK COVERS
    3. HOW THIS BOOK IS STRUCTURED
    4. WHAT YOU NEED TO USE THIS BOOK
    5. CONVENTIONS
    6. SOURCE CODE
    7. ERRATA
    8. P2P.WROX.COM
  7. I. Manipulating and Displaying Data on the iPhone and iPad
    1. 1. Introducing Data-Driven Applications
      1. 1.1. BUILDING A SIMPLE DATA-DRIVEN APPLICATION
        1. 1.1.1. Creating the Project
        2. 1.1.2. Adding a UITableView
          1. 1.1.2.1. Model-View-Controller Architecture
          2. 1.1.2.2. Adding the TableView Programmatically
        3. 1.1.3. Retrieving Data
        4. 1.1.4. Implementing Your Data Model Class
        5. 1.1.5. Displaying the Data
          1. 1.1.5.1. Protocols
          2. 1.1.5.2. Implementing the UITableViewDataSource Protocol
          3. 1.1.5.3. Delegates
          4. 1.1.5.4. Finishing Up
      2. 1.2. FURTHER EXPLORATION
        1. 1.2.1. Design Patterns
        2. 1.2.2. Reading a Text File
      3. 1.3. MOVING FORWARD
    2. 2. The iPhone and iPad Database: SQLite
      1. 2.1. WHAT IS SQLITE?
        1. 2.1.1. The SQLite Library
        2. 2.1.2. SQLite and Core Data
      2. 2.2. BUILDING A SIMPLE DATABASE
        1. 2.2.1. Designing the Database
        2. 2.2.2. Creating the Database
        3. 2.2.3. Populating the Database
          1. 2.2.3.1. Creating Records with the INSERT Command
          2. 2.2.3.2. Reading Your Rows with the SELECT Command
        4. 2.2.4. Tools to Visualize the SQLite Database
      3. 2.3. CONNECTING TO YOUR DATABASE
        1. 2.3.1. Starting the Project
          1. 2.3.1.1. The UINavigationController
          2. 2.3.1.2. The UITableViewController
        2. 2.3.2. The Model Class
        3. 2.3.3. The DBAccess Class
        4. 2.3.4. Parameterized Queries
        5. 2.3.5. Writing to the Database
        6. 2.3.6. Displaying the Catalog
        7. 2.3.7. Viewing Product Details
      4. 2.4. MOVING FORWARD
    3. 3. Displaying Your Data: The UITableView
      1. 3.1. CUSTOMIZING THE TABLEVIEW
        1. 3.1.1. TableViewCell Styles
        2. 3.1.2. Adding Subviews to the contentView
        3. 3.1.3. Subclassing UITableViewCell
          1. 3.1.3.1. Getting Started
          2. 3.1.3.2. Implementing drawRect:
          3. 3.1.3.3. Finishing Up
      2. 3.2. IMPLEMENTING SECTIONS AND AN INDEX
      3. 3.3. IMPLEMENTING SEARCH
      4. 3.4. OPTIMIZING TABLEVIEW PERFORMANCE
        1. 3.4.1. Reusing Existing Cells
        2. 3.4.2. Opaque Subviews
        3. 3.4.3. Custom Drawn Cells with drawRect
        4. 3.4.4. UI Conventions for Accessory Views
      5. 3.5. MOVING FORWARD
    4. 4. iPad Interface Elements
      1. 4.1. DISPLAYING MASTER/DETAIL DATA WITH THE UISPLITVIEWCONTROLLER
        1. 4.1.1. Introducing the UISplitViewController
        2. 4.1.2. The UISplitViewControllerDelegate Protocol
        3. 4.1.3. Starting the Split View Sample Application
        4. 4.1.4. Building the Detail Interface
        5. 4.1.5. Implementing Save and Master/Detail View
          1. 4.1.5.1. Setting Up the DetailViewController
          2. 4.1.5.2. Changes to the RootViewController
          3. 4.1.5.3. Modify the TableView Methods
          4. 4.1.5.4. Adding Surveys
      2. 4.2. DISPLAYING DATA IN A POPOVER
        1. 4.2.1. Building the InfoViewController
        2. 4.2.2. Displaying the UIPopoverController
      3. 4.3. GESTURE RECOGNIZERS
        1. 4.3.1. The UIGestureRecognizer Class
        2. 4.3.2. Using Gesture Recognizers
      4. 4.4. FILE SHARING SUPPORT
        1. 4.4.1. Enable File Sharing in the Sample Application
        2. 4.4.2. Serializing the Survey Data Array
        3. 4.4.3. Deserializing and Loading the Survey Data Array
        4. 4.4.4. Sharing the Data
      5. 4.5. MOVING FORWARD
  8. II. Managing Your Data with Core Data
    1. 5. Introducing Core Data
      1. 5.1. THE BASICS OF CORE DATA
      2. 5.2. THE CORE DATA ARCHITECTURE
        1. 5.2.1. The Core Data Stack
          1. 5.2.1.1. The Data Store
          2. 5.2.1.2. The Persistent Store Coordinator
          3. 5.2.1.3. The Managed Object Model
          4. 5.2.1.4. The Managed Object Context
        2. 5.2.2. SQLite and Core Data
      3. 5.3. USING CORE DATA: A SIMPLE TASK MANAGER
        1. 5.3.1. Creating the Project
        2. 5.3.2. Examining the Template Code
          1. 5.3.2.1. TasksAppDelegate
          2. 5.3.2.2. The Data Model
          3. 5.3.2.3. RootViewController
        3. 5.3.3. Modifying the Template Code
      4. 5.4. MOVING FORWARD
    2. 6. Modeling Data in Xcode
      1. 6.1. MODELING YOUR DATA
        1. 6.1.1. Defining Entities and Their Attributes
          1. 6.1.1.1. Entity Details
          2. 6.1.1.2. Adding Attributes
        2. 6.1.2. Adding Relationships Between Entities
        3. 6.1.3. Creating Fetched Properties and Fetch Request Templates
          1. 6.1.3.1. Fetched Properties
          2. 6.1.3.2. Fetch Request Templates
      2. 6.2. CREATING CUSTOM NSMANAGEDOBJECT SUBCLASSES
        1. 6.2.1. Implementing Validation Rules
        2. 6.2.2. Implementing Default Values
      3. 6.3. CREATING THE TASKS MODEL
      4. 6.4. MOVING FORWARD
    3. 7. Building a Core Data Application
      1. 7.1. THE TASKS APPLICATION ARCHITECTURE
        1. 7.1.1. The Data Model
        2. 7.1.2. The Class Model
        3. 7.1.3. The User Interface
      2. 7.2. CODING THE APPLICATION
      3. 7.3. ROOTVIEWCONTROLLER AND THE BASIC UI
      4. 7.4. GENERATING THE MANAGED OBJECT SUBCLASSES
      5. 7.5. ADDING AND VIEWING TASKS
        1. 7.5.1. Building the ViewTaskController
        2. 7.5.2. Changes to the RootViewController
      6. 7.6. BUILDING THE EDITING CONTROLLERS
        1. 7.6.1. Editing Text with the EditTextController
        2. 7.6.2. Setting Priorities with the EditPriorityController
        3. 7.6.3. Adding and Editing Locations with the EditLocationController
        4. 7.6.4. Modifying Dates with the EditDateController
        5. 7.6.5. Finishing Up the Editing Controllers
      7. 7.7. DISPLAYING RESULTS IN THE ROOTVIEWCONTROLLER
        1. 7.7.1. Sorting Results with NSSortDescriptor
        2. 7.7.2. Filtering Results with NSPredicate
      8. 7.8. GENERATING GROUPED TABLES USING THE NSFETCHEDRESULTSCONTROLLER
      9. 7.9. IMPLEMENTING CUSTOM MANAGED OBJECTS
        1. 7.9.1. Coding a Dynamic Property
        2. 7.9.2. Defaulting Data at Runtime
        3. 7.9.3. Validating a Single Field
        4. 7.9.4. Multi-Field Validation
      10. 7.10. MOVING FORWARD
    4. 8. Core Data–Related Cocoa Features
      1. 8.1. KEY-VALUE CODING
        1. 8.1.1. Keys and Keypaths
        2. 8.1.2. Setting Values Using Keys
        3. 8.1.3. Collection Operators
        4. 8.1.4. Additional Considerations When Using KVC
      2. 8.2. KEY-VALUE OBSERVING
        1. 8.2.1. Observing Changes to an Object
        2. 8.2.2. Automatic and Manual Implementations of KVO
        3. 8.2.3. Key-Value Observing Example
          1. 8.2.3.1. Building the User Interface
          2. 8.2.3.2. The Counter Data Object
          3. 8.2.3.3. Implementing Key-Value Observing
          4. 8.2.3.4. Updating Values with Key-Value Coding
      3. 8.3. USING NSPREDICATE
        1. 8.3.1. Creating Predicates
        2. 8.3.2. Using Predicates
      4. 8.4. SORT DESCRIPTORS
      5. 8.5. MOVING FORWARD
    5. 9. Core Data Migration and Performance
      1. 9.1. MODEL VERSIONING AND SCHEMA MIGRATION
        1. 9.1.1. Model Versioning
        2. 9.1.2. Lightweight Migration
        3. 9.1.3. Generating a Mapping Model
      2. 9.2. SAFELY THREADING WITH CORE DATA
        1. 9.2.1. Designing for Threading
        2. 9.2.2. Threading and Core Data
        3. 9.2.3. Threading with NSOperation
        4. 9.2.4. Core Data Threading Example
          1. 9.2.4.1. Blocking the Main Thread
          2. 9.2.4.2. Moving the Blocking Call
      3. 9.3. CORE DATA PERFORMANCE
        1. 9.3.1. Faulting
        2. 9.3.2. Data Store Types
        3. 9.3.3. Storing Binary Data
        4. 9.3.4. Entity Inheritance
        5. 9.3.5. Runtime Performance
        6. 9.3.6. Managing Changes with the Fetched Results Controller
      4. 9.4. PERFORMANCE ANALYSIS USING INSTRUMENTS
        1. 9.4.1. Starting Instruments
        2. 9.4.2. The Instruments Interface
        3. 9.4.3. The Core Data Instruments
      5. 9.5. MOVING FORWARD
  9. III. Application Integration Using Web Services
    1. 10. Working with XML on the iPhone
      1. 10.1. IPHONE SDK AND THE WEB
        1. 10.1.1. Web Application Architecture
        2. 10.1.2. Synchronous Data Retrieval
        3. 10.1.3. The URL Loading System
        4. 10.1.4. Web Access Sample
          1. 10.1.4.1. Starting the Application
          2. 10.1.4.2. Building the Interface
        5. 10.1.5. Requesting Data from the Server
          1. 10.1.5.1. Creating the Request
          2. 10.1.5.2. NSURLConnection Delegate Methods
          3. 10.1.5.3. Finishing Up
      2. 10.2. XML AND THE IPHONE SDK
        1. 10.2.1. Brief Overview of XML
        2. 10.2.2. Parsing XML with NSXML Parser
        3. 10.2.3. Extending the Example, Parsing the XML
          1. 10.2.3.1. Starting Out
          2. 10.2.3.2. Setting Up to Parse
          3. 10.2.3.3. Modifying the Interface
          4. 10.2.3.4. Implementing the Parser Delegate Methods
        4. 10.2.4. Generating XML with libxml
        5. 10.2.5. XML Generation Sample
      3. 10.3. MOVING FORWARD
    2. 11. Integrating with Web Services
      1. 11.1. NETWORK APPLICATION ARCHITECTURE
        1. 11.1.1. Two-Tier Architecture
        2. 11.1.2. Three-Tier Architecture (n-tier)
        3. 11.1.3. Application Communication
      2. 11.2. INTRODUCING WEB SERVICES
        1. 11.2.1. SOAP Messaging
        2. 11.2.2. The REST Protocol
      3. 11.3. EXAMPLE 1: LOCATION-BASED SEARCH
        1. 11.3.1. Starting Out
        2. 11.3.2. Building the Interface
        3. 11.3.3. Core Location
          1. 11.3.3.1. The Core Location Framework
          2. 11.3.3.2. Using Core Location
        4. 11.3.4. The Local Search API
        5. 11.3.5. Using the Search Bar
        6. 11.3.6. Handling the Web Service Response
          1. 11.3.6.1. The NSURLConnection Delegate Methods
          2. 11.3.6.2. Defining the Result Class
          3. 11.3.6.3. Parsing the Response XML
          4. 11.3.6.4. Using MapKit
          5. 11.3.6.5. Finishing Up
      4. 11.4. EXAMPLE 2: TERM EXTRACTION
        1. 11.4.1. Getting Started
        2. 11.4.2. Building the User Interface
        3. 11.4.3. Implementing the POST Call
        4. 11.4.4. Receiving the XML Response
        5. 11.4.5. Parsing the Response XML
        6. 11.4.6. Finishing Up
      5. 11.5. MOVING FORWARD
  10. A. Tools for Troubleshooting Your Applications
    1. A.1. INSTRUMENTS
      1. A.1.1. Starting Instruments
      2. A.1.2. The Trace Document
      3. A.1.3. Objective-C Memory Management
      4. A.1.4. Sample Memory Leak Application
      5. A.1.5. Analyzing a Memory Leak in Instruments
    2. A.2. THE STATIC ANALYZER