You are previewing Learning the iOS 4 SDK for JavaScript Programmers.
O'Reilly logo
Learning the iOS 4 SDK for JavaScript Programmers

Book Description

Is it possible for JavaScript programmers to learn the iPhone SDK and live to tell the tale? Technology guru Danny Goodman did, and in this book he leaves a well-marked trail for you to follow. Goodman knows the challenges you face with the SDK, so he introduces Objective-C and Cocoa Touch in a context you'll understand. If you're a JavaScript programmer and want to take advantage of the iPhone, this is the book for you.

Table of Contents

  1. Special Upgrade Offer
  2. A Note Regarding Supplemental Files
  3. Preface
    1. What You Need to Start
    2. What’s in This Book
    3. Conventions Used in This Book
    4. Using Code Examples
    5. How to Contact Us
    6. Safari® Books Online
    7. Acknowledgments
  4. 1. Why Go Native?
    1. Using an App Offline
    2. More Access to the Hardware
    3. More Access to the Software
    4. What You Lose
      1. Distribution
      2. Apple iOS Developer Program
      3. Content
      4. Authoring Platform Choices
    5. Taking the Plunge
  5. 2. Welcome to the iOS SDK
    1. Hardware and OS Requirements
    2. Installing the SDK
    3. About iOS Developer Programs
    4. Inside the SDK
    5. Viewing Developer Documentation
    6. Loading Code Samples
    7. Setting the Project’s Base SDK
    8. Trying the iOS Simulator
    9. Coming Up...
  6. 3. Creating a Test Workbench
    1. Creating the Project in Xcode
      1. Selecting a Project Type
      2. Naming and Saving the New Project
      3. Welcome to Your Project
      4. Editing Your First Files
      5. What the runMyCode: Method Does
    2. Building the User Interface
      1. Adding a Button to the View
      2. Connecting the Button
      3. Going for a Test Ride
      4. Congratulations
  7. 4. Structural Overview of an iOS App
    1. Where It All Begins: APIs
      1. APIs You Already Know
      2. The Cocoa Touch APIs
    2. Frameworks
      1. Foundation Framework
      2. UIKit Framework
      3. CoreGraphics Framework
      4. Adding Frameworks
      5. Frameworks Set in Stone
    3. Welcome to Class Files
      1. The JavaScript Way
      2. The Objective-C Way
      3. Header File Details
        1. Importing frameworks
        2. Inheritance
        3. The @interface compiler directive
    4. Using Xcode to Create DGCar Class Files
      1. Editing the @interface Section
      2. Message Passing
      3. Editing the @implementation Section
        1. Adding the getFormattedListing method
        2. Message syntax
        3. Adding the initWithCarMake:model:year: method
    5. Integrating the DGCar Class into Workbench
      1. Creating Object Instances
      2. NSLog() and String Formats
      3. Running the Code
      4. What About Accessing Instance Variables?
    6. Recap
  8. 5. App Execution Flow
    1. Some C Language Roots in an iOS App
    2. An Introduction to Delegates
      1. How UIApplication Appoints Its Delegate
      2. The App’s Info.plist File
      3. Inside MainWindow.xib
    3. iPhone App Development Design Patterns
      1. The Model-View-Controller Design Pattern
      2. Other Design Patterns
    4. The Importance of Views
      1. The App Window—UIWindow
      2. Adding Another View to Workbench
        1. Adding the IBAction method
        2. Creating the user interface
        3. Adding code to display the blue view
    5. Recap
  9. 6. Central Objective-C Concepts: Pointers, Data Types, and Memory Management
    1. Pointers
      1. Pointers and Memory
      2. Pointers and Objective-C Variables
      3. Pointer Notation
      4. Determining Pointer Usage
    2. Data Typing
      1. Objective-C Data Types
      2. Cocoa Touch Data Types
      3. Objective-C Variable Declarations
      4. Objective-C Method Declarations
      5. The id Data Type
      6. Converting Objective-C Data Types
    3. Memory Management
      1. Cleaning Up After Yourself
      2. The Retain Count
      3. Autorelease Pools
      4. Observing Memory Usage
    4. Recap
  10. 7. C Language Fundamentals
    1. Variable Names
    2. Variable Scope
      1. Instance Variables
      2. Local Variables
      3. Local Variables in Control Structure Blocks
      4. Static Local Variables
      5. Global Variables
    3. Constant Values
    4. Functions
    5. C Structures
    6. C Arrays
    7. Enumerated Types
    8. Operators
    9. Program Flow Constructions
    10. Boolean Values
    11. Math Object Equivalents in C
    12. Inserting Comments
    13. Recap
  11. 8. Objective-C/Cocoa Touch Fundamentals
    1. More About Classes
      1. Temporary Objects
      2. Subclassing Framework Classes
      3. Defining Your Own Custom Subclasses
      4. Adding to a Class Without Subclassing—Categories
    2. Real Classes in Real Action
      1. TheElements Overview
      2. TheElements Class File Structure
        1. Single Element View classes
        2. TableView Representations
        3. Data Model
        4. Application Support
        5. Other groups and files
    3. Class Properties
      1. Specifying Properties in the Header File
      2. Synthesizing Properties in the Implementation File
      3. Using Properties
      4. Properties in Framework Classes
    4. About NSString
      1. Creating an NSString
      2. JavaScript String Method Equivalents in Objective-C
        1. Getting single characters and character codes
        2. Appending to a string
        3. Finding the offset of a matching substring
        4. Replacing substrings
        5. Dividing a string into an array
        6. Extracting a substring
        7. Changing case
        8. Escaping and unescaping URL strings
      3. NSMutableString
    5. About NSArray
      1. Creating an NSArray
      2. Retrieving Array Elements
      3. JavaScript Array Method Equivalents in Objective-C
        1. Appending items to an array
        2. Combining array elements into a delimited string
        3. Sorting arrays
      4. NSMutableArray
    6. About NSDictionary
      1. Creating an NSDictionary
      2. Retrieving Dictionary Entries
      3. NSMutableDictionary
    7. Arrays and Dictionaries in Action
    8. Recap
  12. 9. Common JavaScript Tasks in Cocoa Touch
    1. Formatting Numbers for Display
      1. Preformatted Number Styles
      2. Rounding Numbers for Display
    2. Creating a Date Object
      1. Adding a UIDatePicker to Workbench
      2. Understanding NSDate
      3. Creating a Date Object for a Specific Date
      4. Extracting Components from an NSDate Object
      5. Creating NSDate Objects from Strings
      6. Converting an NSDate to a String
    3. Calculating Dates
      1. 10 Days in the Future
      2. Days Between Dates
      3. Comparing Dates
    4. Downloading Remote Files Asynchronously
      1. Example Project
      2. Creating the Request
      3. Initializing the NSMutableData Object
      4. Delegate Methods
        1. Handling download errors
        2. Receiving a response
        3. Accumulating incoming data
        4. Processing the completed download
      5. Downloading Only When Needed
      6. Accounting for Fast App Switching
    5. Reading and Writing Local Files
      1. iOS App Directories
      2. Obtaining Directory Paths
      3. Obtaining Paths to Files Delivered with Your App
      4. Writing Files to Disk
      5. Reading Files from Disk
      6. Writing and Reading Property List Files
      7. Performing File Management Tasks
    6. Sorting Arrays
      1. Sorting with a Selector
      2. Sorting with a Function
      3. Sorting Arrays of Dictionaries with NSSortDescriptor
    7. Capturing User-Entered Text
      1. The Code Portion
      2. The Interface Builder Portion
    8. Validating Text Entry with Regular Expressions
      1. Modifying the Code
      2. Modifying the User Interface
    9. Using Regular Expressions for Text Search and Replace
    10. Dragging a View Around the Screen
      1. The Code Portion
      2. The Interface Builder Portion
    11. Recap
  13. A. Getting the Most from Xcode Documentation
  14. B. Common Beginner Xcode Compiler Errors
    1. Error Messages
    2. Warning Messages
  15. Glossary
  16. Index
  17. About the Author
  18. Colophon
  19. Special Upgrade Offer
  20. Copyright