You are previewing iPhone® Application Development For Dummies®, 2nd Edition.
O'Reilly logo
iPhone® Application Development For Dummies®, 2nd Edition

Book Description

Making Everything Easier!

With iPhone? Application Development for Dummies, Second Edition, you'll learn to:

  • Design small- or large-scale iPhone applications for profit or fun

  • Create new iPhone apps using Xcode?

  • Get your applications into the App Store

  • Work with frameworks

Got a good idea? Turn it into an app, have some fun, and pick up some cash!

Make the most of the new 3.1 OS and Apple's Xcode 3.2! Neal Goldstein shows you how, and even illustrates the process with one of his own apps that's currently being sold. Even if you're not a programming pro, you can turn your bright idea into an app you can market, and Neal even shows you how to get it into the App Store!

  • Mobile is different learn what makes a great app for mobile devices and how an iPhone app is structured

  • What you need download the free Software Development Kit, start using Xcode, and become an "official" iPhone developer

  • The nitty-gritty get the hang of frameworks and iPhone architecture

  • Get busy with apps discover how to make Xcode work for you to support app development

  • Off to the store get valuable advice on getting your apps into the App Store

  • Want to go further? explore what goes into industrial-strength apps

Open the book and find:

  • What it takes to become a registered Apple developer

  • How to debug your app

  • What's new in iPhone 3.1 and Xcode 3.2

  • What goes into a good interface for a small device

  • How applications work in the iPhone environment

  • Why you must think like a user

  • What the App Store expects of you

  • What makes a great iPhone app

Visit the companion Web site at www.dummies.com/go/iphoneappdevfd2e for source code and additional information on iPhone app development.

Table of Contents

  1. Copyright
  2. About The Author
  3. Author's Acknowledgments
  4. Publisher's Acknowledgments
  5. Introduction
    1. About This Book
    2. Conventions Used in This Book
    3. Foolish Assumptions
    4. How This Book Is Organized
      1. Part I: Getting Started
      2. Part II: Using the iPhone Development Tools
      3. Part III: From "Gee, That's a Good Idea," to the App Store
      4. Part IV: An Industrial-Strength Application
      5. Part V: The Part of Tens
    5. Icons Used in This Book
    6. Where to Go from Here
  6. I. Getting Started
    1. 1. Creating Killer iPhone Applications
      1. 1.1. What Makes a Great iPhone Application
      2. 1.2. Creating a Compelling User Experience
      3. 1.3. Exploiting the Platform
        1. 1.3.1. Device-guided design
        2. 1.3.2. Exploiting the features
          1. 1.3.2.1. Accessing the Internet
          2. 1.3.2.2. Knowing the location of the user
          3. 1.3.2.3. Tracking orientation and motion
          4. 1.3.2.4. Tracking the action of the user's fingers on the screen
          5. 1.3.2.5. Playing audio and video
          6. 1.3.2.6. Accessing the user's contacts
          7. 1.3.2.7. Accessing the user's pictures and camera
        3. 1.3.3. Embracing the limitations
          1. 1.3.3.1. Living with the small screen
          2. 1.3.3.2. Designing for fingers
          3. 1.3.3.3. Limited computer power, memory, and battery life
      4. 1.4. A Compelling User Experience
        1. 1.4.1. Compelling content
          1. 1.4.1.1. Consistency with the user's world
        2. 1.4.2. The user interface — form following function
          1. 1.4.2.1. Consistency
          2. 1.4.2.2. Making it obvious
          3. 1.4.2.3. Engaging the user
      5. 1.5. Why Develop iPhone Applications?
      6. 1.6. Examining the Possibilities
      7. 1.7. The Sample Applications
      8. 1.8. What's Next
    2. 2. Looking Behind the Screen
      1. 2.1. Using Frameworks
      2. 2.2. Using Design Patterns
        1. 2.2.1. The Model-View-Controller (MVC) pattern
        2. 2.2.2. The MVC in action
      3. 2.3. Working with Windows and Views
        1. 2.3.1. Looking out the window
        2. 2.3.2. Admiring the view
          1. 2.3.2.1. What views do
          2. 2.3.2.2. The view hierarchy
        3. 2.3.3. The kinds of views you use
          1. 2.3.3.1. Container views
          2. 2.3.3.2. Controls
          3. 2.3.3.3. Display views
          4. 2.3.3.4. Text and Web views
          5. 2.3.3.5. Alert views and action sheets
          6. 2.3.3.6. Navigation views
          7. 2.3.3.7. The window
      4. 2.4. Controlling View Controllers
      5. 2.5. What about the Model?
      6. 2.6. Adding Your Own Application's Behavior
        1. 2.6.1. The Delegation pattern
        2. 2.6.2. The Target-Action pattern
      7. 2.7. Doing What When?
      8. 2.8. Whew!
    3. 3. Enlisting in the Developer Corps
      1. 3.1. Becoming a Registered iPhone Developer
      2. 3.2. Exploring the iPhone Dev Center
        1. 3.2.1. Looking forward to using the SDK
        2. 3.2.2. Resources on the iPhone Dev Center
      3. 3.3. Downloading the SDK
      4. 3.4. Joining the iPhone Developer Program
      5. 3.5. Getting Yourself Ready for the SDK
  7. II. Using the iPhone Development Tools
    1. 4. Getting to Know the SDK
      1. 4.1. Developing Using the SDK
      2. 4.2. Creating Your Project
      3. 4.3. Exploring Your Project
      4. 4.4. Building and Running Your Application
      5. 4.5. The iPhone Simulator
        1. 4.5.1. Hardware interaction
        2. 4.5.2. Gestures
        3. 4.5.3. Uninstalling applications and resetting your device
        4. 4.5.4. Limitations
      6. 4.6. Customizing Xcode to Your Liking
      7. 4.7. Using Interface Builder
      8. 4.8. It's Time to Get to Work
    2. 5. Building the User Interface
      1. 5.1. Starting Interface Builder
      2. 5.2. Adding Graphics and the Rest of the Elements
      3. 5.3. Adding an Application Icon
      4. 5.4. A Lot Accomplished Very Quickly
    3. 6. While Your Application Is Running
      1. 6.1. Application Anatomy 101 — The Life Cycle
        1. 6.1.1. It all starts with the main nib file
        2. 6.1.2. Initialization
      2. 6.2. Event Processing
      3. 6.3. Termination
      4. 6.4. Other Runtime Considerations
        1. 6.4.1. Responding to interruptions
        2. 6.4.2. Seeing how memory management works on the iPhone
          1. 6.4.2.1. Observing low-memory warnings
          2. 6.4.2.2. Avoiding the warnings
          3. 6.4.2.3. Some basic memory-management rules you shouldn't forget
          4. 6.4.2.4. Reread this section!
      5. 6.5. Whew!
  8. III. From "Gee, That's a Good Idea," to the App Store
    1. 7. Actually Writing Code
      1. 7.1. Buckle Up, It's Time to Code
      2. 7.2. The Xcode Code Editor
      3. 7.3. Accessing Documentation
        1. 7.3.1. Quick Help
        2. 7.3.2. The header file for a symbol
        3. 7.3.3. Documentation window
        4. 7.3.4. Help menu
        5. 7.3.5. Find
      4. 7.4. Adding Outlets to the View Controller
        1. 7.4.1. Objective-C properties
      5. 7.5. Memory Management
      6. 7.6. Connecting the Pieces in Interface Builder
    2. 8. Entering and Managing Data
      1. 8.1. Scrolling the View
      2. 8.2. Where Does My Code Go?
        1. 8.2.1. The Delegate object
        2. 8.2.2. The Controller object
      3. 8.3. Where Where Where
      4. 8.4. Building on a Foundation
        1. 8.4.1. Notification
          1. 8.4.1.1. Registering a notification
          2. 8.4.1.2. Unregistering a notification
        2. 8.4.2. Keeping the text field visible
          1. 8.4.2.1. The concept
          2. 8.4.2.2. The mechanics of scrolling the view
        3. 8.4.3. Moving the view
        4. 8.4.4. Updating the interface
        5. 8.4.5. Lowering the view when all is said and done
      5. 8.5. Polishing the Chrome and Adding the Vinyl Pinstriping
        1. 8.5.1. Adopting a protocol
        2. 8.5.2. Connecting things up with Interface Builder
        3. 8.5.3. Adding a Clear button
        4. 8.5.4. Saving the phone number for future reference
        5. 8.5.5. Dismissing the keyboard when the user touches in the view
      6. 8.6. Finding Your Way Around the Code
      7. 8.7. When You're Done
    3. 9. Saving Data and Creating a Secret Button
      1. 9.1. Saving User-Entry Data
        1. 9.1.1. Preferences
          1. 9.1.1.1. The NSUserDefaults class
        2. 9.1.2. Saving data using NSUserDefaults
          1. 9.1.2.1. Setting it up
          2. 9.1.2.2. Saving the phone number
          3. 9.1.2.3. Loading the preference entry to get the data
          4. 9.1.2.4. Using data
      2. 9.2. Disabling Editing
      3. 9.3. Letting the User Use the Secret Button
      4. 9.4. What You Have Now — At Long Last
    4. 10. Using the Debugger
      1. 10.1. Using the Debugger
        1. 10.1.1. Debugging your project
        2. 10.1.2. Using the Debugger window
      2. 10.2. Using Breakpoints
      3. 10.3. Using the Static Analyzer
      4. 10.4. One More Step
    5. 11. Buttoning It Down and Calling Home
      1. 11.1. Adding a Button to Your iPhone Interface
        1. 11.1.1. The Target-Action pattern
        2. 11.1.2. Working through your button code
      2. 11.2. Connecting the Button in Interface Builder
      3. 11.3. Phoning Home
        1. 11.3.1. Tweaking the code
        2. 11.3.2. Implementing the Web view
        3. 11.3.3. Adding and connecting the Web View in Interface Builder
      4. 11.4. A Bug
      5. 11.5. We Are Finally Done
      6. 11.6. The Final Code
    6. 12. Death, Taxes, and the iPhone Provisioning
      1. 12.1. How the Process Works
        1. 12.1.1. The Distribution process
        2. 12.1.2. The Development process
      2. 12.2. Provisioning Your Device for Development
        1. 12.2.1. Development Provisioning Profile and iPhone Development Certificate
      3. 12.3. Provisioning Your Application for the App Store
      4. 12.4. iTunes Connect
        1. 12.4.1. What you'll need to get your application into the App Store
        2. 12.4.2. We're not done yet
        3. 12.4.3. Uploading your information
        4. 12.4.4. Upload your application and its data
      5. 12.5. Now What?
  9. IV. An Industrial-Strength Application
    1. 13. Designing Your Application
      1. 13.1. Defining the Problems
      2. 13.2. Designing the User Experience
        1. 13.2.1. Understanding the real-world context
          1. 13.2.1.1. Become the champion of relevance
          2. 13.2.1.2. Seconds count
          3. 13.2.1.3. The quality of information has to be better than the alternative
          4. 13.2.1.4. The app has to be worth the real cost
          5. 13.2.1.5. Keep things localized
        2. 13.2.2. Paying particular attention to three iPhone features
          1. 13.2.2.1. Knowing the location of the user
          2. 13.2.2.2. Accessing the Internet
          3. 13.2.2.3. Tracking orientation and motion
        3. 13.2.3. Incorporating the device context
        4. 13.2.4. Categorizing the problems and defining the solutions
      3. 13.3. Creating the Program Architecture
        1. 13.3.1. A main view
        2. 13.3.2. Content views
        3. 13.3.3. View controllers
        4. 13.3.4. Models
          1. 13.3.4.1. No use reinventing the wheel
          2. 13.3.4.2. Putting property lists to good use
        5. 13.3.5. Stored data mode, saving state, and localization
      4. 13.4. The Iterative Nature of the Process
    2. 14. Setting the Table
      1. 14.1. Working with Table Views
        1. 14.1.1. Creating the table view
        2. 14.1.2. Creating and formatting a grouped table view
        3. 14.1.3. Making UITableViewController work for you
          1. 14.1.3.1. Adding sections
          2. 14.1.3.2. Adding titles for the sections
          3. 14.1.3.3. Localization
        4. 14.1.4. Creating the row model
        5. 14.1.5. Seeing how cells work
          1. 14.1.5.1. Using vanilla cell objects
          2. 14.1.5.2. Adding subviews to a cell's content view
          3. 14.1.5.3. Creating a custom subclass UITableViewCell
        6. 14.1.6. Creating the cell
        7. 14.1.7. Responding to a selection
        8. 14.1.8. Navigating the navigation controller
        9. 14.1.9. Implementing the selection
      2. 14.2. And Now ...
    3. 15. Enhancing the User Experience
      1. 15.1. Saving and Restoring State
        1. 15.1.1. Saving state information
        2. 15.1.2. Restoring the state
      2. 15.2. Respecting User Preferences
        1. 15.2.1. Adding a Settings bundle to your project
        2. 15.2.2. Setting up the property list
      3. 15.3. Reading Settings in the Application
      4. 15.4. Using Preferences in Your Application
      5. 15.5. This App Is Almost Done
    4. 16. Creating Controllers and Their Models
      1. 16.1. Specifying the Content
      2. 16.2. Creating the View Controller, Nib, and Model Files
        1. 16.2.1. Adding the controller and nib file
        2. 16.2.2. Adding the model class
        3. 16.2.3. Set up the nib file
      3. 16.3. Implementing the View, View Controller, and the Model
        1. 16.3.1. Make sure the AirportController knows about the objects it needs
        2. 16.3.2. Initialization
        3. 16.3.3. Setting up the view
        4. 16.3.4. Responding to the user selection
      4. 16.4. The Destination Model
      5. 16.5. What's with the Destination Model and All That Indirection
      6. 16.6. The Weather Implementation Model
      7. 16.7. The Currency Implementation Model
      8. 16.8. Notice the Pattern
      9. 16.9. What's Next?
    5. 17. Finding Your Way
      1. 17.1. Using MapKit
      2. 17.2. MKMapView
      3. 17.3. Enhancing the Map
        1. 17.3.1. Adding landscape mode and the current location
        2. 17.3.2. It's about the region
      4. 17.4. Annotations
        1. 17.4.1. The annotation
        2. 17.4.2. Displaying the annotations
      5. 17.5. Going to the Current Location
      6. 17.6. Geocoding
      7. 17.7. What's Next?
  10. V. The Part of Tens
    1. 18. Top Ten Apple Sample Applications (with Code!)
      1. 18.1. AppPrefs
      2. 18.2. BubbleLevel
      3. 18.3. LocateMe
      4. 18.4. NavBar
      5. 18.5. Reachability
      6. 18.6. iPhoneCoreDataRecipes
      7. 18.7. UICatalog
      8. 18.8. URLCache
      9. 18.9. XML
      10. 18.10. Tables
    2. 19. Ten Ways to Be a Happy Developer
      1. 19.1. It's Never Early Enough to Start Speaking a Foreign Language
      2. 19.2. Remember Memory
      3. 19.3. Constantly Use Constants
      4. 19.4. Don't Fall Off the Cutting Edge
      5. 19.5. Start by Initializing the Right Way
      6. 19.6. Keep the Order Straight
      7. 19.7. Avoid Mistakes in Error Handling
      8. 19.8. Remember the User
      9. 19.9. Keep in Mind that the Software Isn't Finished Until the Last User Is Dead
      10. 19.10. Keep It Fun