Cover image for Programming iOS 6, 3rd Edition

Book description

Get a solid grounding in all the fundamentals of Cocoa Touch, and avoid problems during iPhone and iPad app development. With this revised and expanded edition, you’ll dig into Cocoa and learn how to work effectively with Objective-C and Xcode. This book covers iOS 6 in a rigorous, orderly fashion—ideal whether you’re approaching iOS for the first time or need a reference to bolster existing skills.

Table of Contents

  1. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. Safari® Books Online
    4. How to Contact Us
    5. Acknowledgments for the First Edition
    6. Notes on the Second Printing
    7. Acknowledgments for the Second Edition
    8. Notes on the Second Edition
    9. Acknowledgments for the Third Edition
    10. Notes on the Third Edition
  2. I. Language
    1. 1. Just Enough C
      1. Compilation, Statements, and Comments
      2. Variable Declaration, Initialization, and Data Types
      3. Structs
      4. Pointers
      5. Arrays
      6. Operators
      7. Flow Control and Conditions
      8. Functions
      9. Pointer Parameters and the Address Operator
      10. Files
      11. The Standard Library
      12. More Preprocessor Directives
      13. Data Type Qualifiers
    2. 2. Object-Based Programming
      1. Objects
      2. Messages and Methods
      3. Classes and Instances
      4. Class Methods
      5. Instance Variables
      6. The Object-Based Philosophy
    3. 3. Objective-C Objects and Messages
      1. An Instance Reference Is a Pointer
        1. Instance References, Initialization, and nil
        2. Instance References and Assignment
        3. Instance References and Memory Management
      2. Messages and Methods
        1. Sending a Message
        2. Declaring a Method
        3. Nesting Method Calls
        4. No Overloading
        5. Parameter Lists
        6. Unrecognized Selectors
      3. Typecasting and the id Type
      4. Messages as Data Type
      5. C Functions
      6. CFTypeRefs
      7. Blocks
    4. 4. Objective-C Classes
      1. Class and Superclass
      2. Interface and Implementation
      3. Header File and Implementation File
      4. Class Methods
      5. The Secret Life of Classes
    5. 5. Objective-C Instances
      1. How Instances Are Created
        1. Ready-Made Instances
        2. Instantiation from Scratch
          1. Initialization
          2. The designated initializer
        3. Nib-Based Instantiation
      2. Polymorphism
      3. The Keyword self
      4. The Keyword super
      5. Instance Variables and Accessors
      6. Key–Value Coding
      7. Properties
      8. How to Write an Initializer
  3. II. IDE
    1. 6. Anatomy of an Xcode Project
      1. New Project
      2. The Project Window
        1. The Navigator Pane
        2. The Utilities Pane
        3. The Editor
      3. The Project File and Its Dependents
      4. The Target
        1. Build Phases
        2. Build Settings
        3. Configurations
        4. Schemes and Destinations
      5. From Project to App
        1. Build Settings
        2. Property List Settings
        3. Nib Files and Storyboard Files
        4. Other Resources
        5. Code
        6. Frameworks and SDKs
    2. 7. Nib Management
      1. A Tour of the Nib-Editing Interface
        1. The Dock
        2. Canvas
        3. Inspectors and Libraries
      2. Nib Loading and File’s Owner
      3. Making and Loading a Nib
      4. Outlet Connections
        1. More Ways to Create Outlets
        2. More About Outlets
      5. Action Connections
      6. Additional Initialization of Nib-Based Instances
    3. 8. Documentation
      1. The Documentation Window
      2. Class Documentation Pages
      3. Sample Code
      4. Other Resources
        1. Quick Help
        2. Symbols
        3. Header Files
        4. Internet Resources
    4. 9. Life Cycle of a Project
      1. Device Architecture and Conditional Code
      2. Localization
      3. Editing Your Code
        1. Autocompletion
        2. Snippets
        3. Fix-it and Live Syntax Checking
      4. Navigating Your Code
      5. Debugging
        1. Caveman Debugging
        2. The Xcode Debugger
      6. Unit Testing
      7. Static Analyzer
      8. Clean
      9. Running in the Simulator
      10. Running on a Device
      11. Profile and Device Management
      12. Version Control
      13. Instruments
      14. Distribution
      15. Ad Hoc Distribution
      16. Final App Preparations
        1. Icons in the App
        2. Other Icons
        3. Launch Images
        4. Screenshots
        5. Property List Settings
      17. Submission to the App Store
  4. III. Cocoa
    1. 10. Cocoa Classes
      1. Subclassing
      2. Categories
        1. Splitting a Class
        2. Class Extensions
      3. Protocols
      4. Optional Methods
      5. Some Foundation Classes
        1. Useful Structs and Constants
        2. NSString and Friends
        3. NSDate and Friends
        4. NSNumber
        5. NSValue
        6. NSData
        7. Equality and Comparison
        8. NSIndexSet
        9. NSArray and NSMutableArray
        10. NSSet and Friends
        11. NSDictionary and NSMutableDictionary
        12. NSNull
        13. Immutable and Mutable
        14. Property Lists
      6. The Secret Life of NSObject
    2. 11. Cocoa Events
      1. Reasons for Events
      2. Subclassing
      3. Notifications
        1. Receiving a Built-In Notification
        2. Unregistering
        3. NSTimer
      4. Delegation
      5. Data Sources
      6. Actions
      7. The Responder Chain
        1. Deferring Responsibility
        2. Nil-Targeted Actions
      8. Swamped by Events
      9. Delayed Performance
      10. Application Lifetime Events
    3. 12. Accessors and Memory Management
      1. Key–Value Coding
        1. KVC and Outlets
        2. Key Paths and Array Accessors
      2. Memory Management
        1. Principles of Cocoa Memory Management
        2. The Golden Rules of Memory Management
        3. What ARC Is and What It Does
        4. How Cocoa Objects Manage Memory
        5. Autorelease
        6. Memory Management of Instance Variables (Non-ARC)
        7. Memory Management of Instance Variables (ARC)
        8. Retain Cycles and Weak References
        9. Unusual Memory Management Situations
        10. Nib Loading and Memory Management
        11. Memory Management of Global Variables
        12. Memory Management of Pointer-to-Void Context Info
        13. Memory Management of CFTypeRefs
      3. Properties
        1. Property Memory Management Policies
        2. Property Declaration Syntax
        3. Property Accessor Synthesis
        4. Dynamic Accessors
    4. 13. Data Communication
      1. Model–View–Controller
      2. Instance Visibility
        1. Visibility by Instantiation
        2. Visibility by Relationship
        3. Global Visibility
      3. Notifications
      4. Key–Value Observing
  5. IV. Views
    1. 14. Views
      1. The Window
      2. Subview and Superview
      3. Visibility and Opacity
      4. Frame
      5. Bounds and Center
      6. Transform
      7. Layout
        1. Autoresizing
        2. Autolayout
        3. Constraints in the Nib
        4. Order of Layout Events
        5. Autolayout and View Transforms
    2. 15. Drawing
      1. UIImage and UIImageView
      2. Graphics Contexts
      3. UIImage Drawing
      4. CGImage Drawing
      5. CIFilter and CIImage
      6. Drawing a UIView
      7. Graphics Context Settings
      8. Paths and Drawing
      9. Clipping
      10. Gradients
      11. Colors and Patterns
      12. Graphics Context Transforms
      13. Shadows
      14. Points and Pixels
      15. Content Mode
    3. 16. Layers
      1. View and Layer
      2. Layers and Sublayers
        1. Manipulating the Layer Hierarchy
        2. Positioning a Sublayer
        3. CAScrollLayer
        4. Layout of Sublayers
      3. Drawing in a Layer
        1. Content Resizing and Positioning
        2. Layers that Draw Themselves
      4. Transforms
        1. Depth
      5. Shadows, Borders, and More
      6. Layer Efficiency
      7. Layers and Key–Value Coding
    4. 17. Animation
      1. Drawing, Animation, and Threading
      2. UIImageView and UIImage Animation
      3. View Animation
        1. Animation Blocks
        2. Modifying an Animation Block
        3. Transition Animations
        4. Block-Based View Animation
      4. Implicit Layer Animation
        1. Animation Transactions
        2. Media Timing Functions
      5. Core Animation
        1. CABasicAnimation and Its Inheritance
        2. Using a CABasicAnimation
        3. Keyframe Animation
        4. Making a Property Animatable
        5. Grouped Animations
        6. Transitions
        7. The Animations List
      6. Animation and Autolayout
      7. Actions
        1. What an Action Is
        2. The Action Search
        3. Hooking Into the Action Search
        4. Nonproperty Actions
      8. Emitter Layers
      9. CIFilter Transitions
    5. 18. Touches
      1. Touch Events and Views
      2. Receiving Touches
      3. Restricting Touches
      4. Interpreting Touches
      5. Gesture Recognizers
        1. Gesture Recognizer Classes
        2. Multiple Gesture Recognizers
        3. Subclassing Gesture Recognizers
        4. Gesture Recognizer Delegate
        5. Gesture Recognizers in the Nib
      6. Touch Delivery
        1. Hit-Testing
          1. Hit-testing for layers
          2. Hit-testing for drawings
          3. Hit-testing during animation
        2. Initial Touch Event Delivery
        3. Gesture Recognizer and View
        4. Touch Exclusion Logic
        5. Recognition
        6. Touches and the Responder Chain
  6. V. Interface
    1. 19. View Controllers
      1. The View Controller Hierarchy
      2. View Controller and View Creation
        1. Manual View
        2. Generic Automatic View
        3. View in a Separate Nib
        4. Nib-Instantiated View Controller
        5. Storyboard-Instantiated View Controller
      3. Rotation
        1. Rotation and Layout Events
        2. Initial Orientation
      4. Presented View Controller
        1. Presented View Animation
        2. Presentation Styles
        3. Rotation of a Presented View
        4. Presenting a View in Response to Rotation
      5. Tab Bar Controllers
        1. Tab Bar Items
        2. Configuring a Tab Bar Controller
      6. Navigation Controllers
        1. Bar Button Items
        2. Navigation Items
        3. Toolbar Items
        4. Configuring a Navigation Controller
      7. Page View Controller
      8. Container View Controllers
      9. Storyboards
        1. Segues
        2. Unwind Segues
        3. Storyboards and Custom Container View Controllers
      10. View Controller Lifetime Events
      11. View Controller Memory Management
      12. State Restoration
        1. Participating in State Restoration
        2. Restoration ID and Restoration Class
        3. Restoring View Controller State
    2. 20. Scroll Views
      1. Creating a Scroll View
      2. Scrolling
        1. Paging
        2. Tiling
      3. Zooming
        1. Zooming Programmatically
        2. Zooming with Detail
      4. Scroll View Delegate
      5. Scroll View Touches
      6. Scroll View Performance
    3. 21. Table Views and Collection Views
      1. Table View Cells
        1. Built-In Cell Styles
        2. Registering a Cell Class
        3. Custom Cells
          1. Overriding a cell’s subview layout
          2. Adding subviews in code
          3. Designing a cell in a nib
          4. Designing a cell in a storyboard
      2. Table View Data
        1. The Three Big Questions
        2. Table View Sections
        3. Refreshing Table View Data
        4. Variable Row Heights
      3. Table View Selection
      4. Table View Scrolling and Layout
      5. Table View State Restoration
      6. Table View Searching
      7. Table View Editing
        1. Deleting Table Items
        2. Editable Content in Table Items
        3. Inserting Table Items
        4. Rearranging Table Items
        5. Dynamic Table Content
      8. Table View Menus
      9. Collection Views
    4. 22. Popovers and Split Views
      1. Configuring and Displaying a Popover
      2. Managing a Popover
      3. Dismissing a Popover
      4. Popovers and Presented Views
      5. Popover Segues
      6. Automatic Popovers
      7. Split Views
    5. 23. Text
      1. Attributed Strings
      2. UILabel
      3. UITextField
        1. Summoning and Dismissing the Keyboard
        2. Keyboard Covers Text Field
        3. Configuring the Keyboard
        4. Text Field Delegate and Control Event Messages
        5. The Text Field Menu
      4. UITextView
      5. Core Text
    6. 24. Web Views
      1. Loading Web View Content
      2. Web View State Restoration
      3. Communicating with a Web View
    7. 25. Controls and Other Views
      1. UIActivityIndicatorView
      2. UIProgressView
      3. UIPickerView
      4. UISearchBar
      5. UIControl
        1. UISwitch
        2. UIStepper
        3. UIPageControl
        4. UIDatePicker
        5. UISlider
        6. UISegmentedControl
        7. UIButton
        8. Custom Controls
      6. Bars
        1. UINavigationBar
        2. UIToolbar
        3. UITabBar
      7. Appearance Proxy
    8. 26. Modal Dialogs
      1. Alert View
      2. Action Sheet
      3. Dialog Alternatives
      4. Local Notifications
      5. Activity View
  7. VI. Some Frameworks
    1. 27. Audio
      1. System Sounds
      2. Audio Session
        1. Interruptions
        2. Routing Changes
      3. Audio Player
      4. Remote Control of Your Sound
      5. Playing Sound in the Background
      6. Further Topics in Sound
    2. 28. Video
      1. MPMoviePlayerController
      2. MPMoviePlayerViewController
      3. UIVideoEditorController
      4. Introduction to AV Foundation Video
    3. 29. Music Library
      1. Exploring the Music Library
      2. The Music Player
      3. The Music Picker
    4. 30. Photo Library and Image Capture
      1. UIImagePickerController
        1. Choosing from the Photo Library
        2. Using the Camera
      2. Image Capture With AV Foundation
      3. The Assets Library Framework
    5. 31. Address Book
      1. Address Book Database
      2. Address Book Interface
        1. ABPeoplePickerNavigationController
        2. ABPersonViewController
        3. ABNewPersonViewController
        4. ABUnknownPersonViewController
    6. 32. Calendar
      1. Calendar Database
      2. Calendar Interface
    7. 33. Mail and Messages
      1. Mail Message
      2. Text Message
      3. Twitter Post
    8. 34. Maps
      1. Displaying a Map
      2. Annotations
      3. Overlays
      4. Map Kit and Current Location
      5. Geocoding
      6. Communicating With the Maps App
    9. 35. Sensors
      1. Location
      2. Heading
      3. Acceleration and Attitude
        1. Shake Events
        2. Raw Acceleration
        3. Gyroscope
  8. VII. Final Topics
    1. 36. Persistent Storage
      1. The Sandbox
      2. Basic File Operations
      3. Saving and Reading Files
      4. User Defaults
      5. File Sharing
      6. Document Types
      7. Handing Off a Document
      8. The Document Architecture
      9. iCloud
      10. XML
      11. SQLite
      12. Core Data
      13. Image File Formats
    2. 37. Basic Networking
      1. HTTP Requests
      2. Bonjour
      3. Push Notifications
      4. Beyond Basic Networking
    3. 38. Threads
      1. The Main Thread
      2. Why Threading Is Hard
      3. Three Ways of Threading
        1. Manual Threads
        2. NSOperation
        3. Grand Central Dispatch
      4. Threads and App Backgrounding
    4. 39. Undo
      1. The Undo Manager
      2. The Undo Interface
      3. The Undo Architecture
    5. 40. Epilogue
  9. Index
  10. About the Author
  11. Colophon
  12. Copyright