Professional iPhone and iPad database application programming

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