You are previewing iOS® 9 Application Development in 24 Hours, Sams Teach Yourself, Seventh Edition.
O'Reilly logo
iOS® 9 Application Development in 24 Hours, Sams Teach Yourself, Seventh Edition

Book Description

Covers iOS 9.1 and up, Xcode 7.x, iPhone, iPad, and More!

In just 24 sessions of one hour each, learn how to build powerful applications for today’s hottest handheld devices: the iPhone and iPad! Using this book’s straightforward, step-by-step approach, you’ll master every skill and technology you need, from setting up your iOS development environment to building great user interfaces, sensing motion to writing multitasking applications. Each lesson builds on what you’ve already learned, giving you a rock-solid foundation for real-world success!

Step-by-step instructions carefully walk you through the most common iOS development tasks.
Quizzes and Exercises help you test your knowledge.
Notes present interesting information related to the discussion.
Tips show you easier ways to perform tasks.
Cautions alert you to possible problems and give you advice on how to avoid them.

Printed in full color—figures and code appear as they do in Xcode 7.x
• Learn to navigate the Xcode 7.x development environment and install apps on your iDevice
• Get started quickly with Apple’s Open Source language: Swift 2.0
• Test code and application logic using the iOS Playground
• Understand the Model-View-Controller (MVC) development pattern
• Visually design and code interfaces using Xcode Storyboards, Segues, Exits, Image Slicing, and the iOS Object Library
• Use Auto Layout and Size Classes to adapt to different screen sizes and orientations
• Build advanced UIs with Tables, Split Views, Navigation Controllers, and more
• Read and write preferences and data, and create System Settings plug-ins
• Use iOS media playback and recording capabilities
• Take photos and manipulate graphics with Core Image
• Sense motion, orientation, and location with the accelerometer, gyroscope, and GPS
• Use 3D touch to add Peek, Pop, and Quick Actions to your apps
• Integrate online services using Twitter, Facebook, Email, Web Views, and Apple Maps
• Create universal applications that run on both the iPhone and iPad
• Write background-aware multitasking applications
• Trace, debug, and monitor applications as they run
• Additional files and updates available online


Table of Contents

  1. About This E-Book
  2. Title Page
  3. Copyright Page
  4. Contents at a Glance
  5. Table of Contents
  6. About the Author
  7. Dedication
  8. Acknowledgments
  9. We Want to Hear from You!
  10. Reader Services
  11. Introduction
    1. Who Can Become an iOS Developer?
    2. Who Should Use This Book?
    3. What Is (and Isn’t) in This Book?
  12. Hour 1. Preparing Your System and iDevice for Development
    1. Welcome to the iOS Platform
      1. IOS Devices
      2. Display and Graphics
      3. Application Resource Constraints
      4. Connectivity
      5. Input and Feedback
    2. Becoming an iOS Developer
      1. The Apple Developer Program
      2. Becoming a Paid Developer Member
      3. Installing Xcode
    3. Running an iOS App
      1. What’s a Development Provisioning Profile?
      2. Configuring Devices for Development
      3. Launching the App
    4. Developer Technology Overview
      1. The Apple Developer Tools
      2. Swift
      3. Cocoa Touch
      4. Model-View-Controller
    5. Further Exploration
    6. Summary
    7. Q&A
    8. Workshop
      1. Quiz
      2. Answers
    9. Activities
  13. Hour 2. Introduction to Xcode and the iOS Simulator
    1. Using Xcode
      1. Creating and Managing Projects
      2. Editing and Navigating Code
      3. Building Applications
      4. Managing Project Properties
      5. Setting Supported Device Orientations
      6. Application Icons, Launch Images, and Launch Screens
    2. Using the iOS Simulator
      1. Launching Applications
      2. Generating Multitouch Events
      3. Rotating the Simulated Device
      4. Testing Other Conditions
      5. Adding Additional Simulated Devices
    3. Further Exploration
    4. Summary
    5. Q&A
    6. Workshop
      1. Quiz
      2. Answers
    7. Activities
  14. Hour 3. Discovering Swift and the iOS Playground
    1. Object-Oriented Programming and Swift
      1. What Is Object-Oriented Programming?
    2. The Terminology of Object-Oriented Development
      1. What Is Swift?
    3. Exploring the Swift File Structure
      1. Class Files
      2. Structure for Free
    4. Swift Programming Basics
      1. Declaring Variables and Constants
      2. Using Methods
      3. Expressions and Decision Making
    5. Memory Management and Automatic Reference Counting
    6. Introducing the iOS Playground
      1. Creating a New Playground
      2. Using the Playground
      3. Generating and Inspecting Output
    7. Further Exploration
    8. Summary
    9. Q&A
    10. Workshop
      1. Quiz
      2. Answers
    11. Activities
  15. Hour 4. Inside Cocoa Touch
    1. What Is Cocoa Touch?
      1. Keeping Your Cool in the Face of Overwhelming Functionality
      2. Young, Yet Mature
    2. Exploring the iOS Technology Layers
      1. The Cocoa Touch Layer
      2. The Media Layer
      3. The Core Services Layer
      4. The Core OS Layer
    3. Tracing the iOS Application Life Cycle
    4. Cocoa Fundamentals
      1. Core Application Classes
      2. Data Type Classes
      3. Interface Classes
    5. Exploring the iOS Frameworks with Xcode
      1. Xcode Documentation
      2. Quick Help
    6. Further Exploration
    7. Summary
    8. Q&A
    9. Workshop
      1. Quiz
      2. Answers
    10. Activities
  16. Hour 5. Exploring Interface Builder
    1. Understanding Interface Builder
      1. The IB Approach
      2. The Anatomy of an IB Storyboard
    2. Creating User Interfaces
      1. The Object Library
      2. Adding Objects to a View
      3. Working with the IB Editing Tools
      4. The Auto Layout System
    3. Customizing the Interface Appearance
      1. Using the Attributes Inspector
      2. Setting Accessibility Attributes
      3. Previewing the Interface
    4. Connecting to Code
      1. Opening the Project
      2. Implementation Overview
      3. Outlets and Actions
      4. Object Identity
    5. Further Exploration
    6. Summary
    7. Q&A
    8. Workshop
      1. Quiz
      2. Answers
    9. Activities
  17. Hour 6. Model-View-Controller Application Design
    1. Understanding the MVC Design Pattern
      1. Making Spaghetti
      2. Structured Application Design with MVC
    2. How Xcode Implements MVC
      1. Views
      2. View Controllers
      3. Data Models
    3. Using the Single View Application Template
      1. Implementation Overview
      2. Setting Up the Project
      3. Planning the Variables and Connections
      4. Designing the Interface
      5. Creating and Connecting the Outlets and Actions
      6. Implementing the Application Logic
      7. Building the Application
    4. Further Exploration
    5. Summary
    6. Q&A
    7. Workshop
      1. Quiz
      2. Answers
    8. Activities
  18. Hour 7. Working with Text, Keyboards, and Buttons
    1. Basic User Input and Output
      1. Buttons
      2. Text Fields and Views
      3. Labels
    2. Using Text Fields, Text Views, and Buttons
      1. Implementation Overview
      2. Setting Up the Project
      3. Preparing Button Templates with Slicing
      4. Designing the Interface
      5. Creating and Connecting the Outlets and Actions
      6. Implementing Keyboard Hiding
      7. Implementing the Application Logic
      8. Building the Application
    3. Further Exploration
    4. Summary
    5. Q&A
    6. Workshop
      1. Quiz
      2. Answers
    7. Activities
  19. Hour 8. Handling Images, Animation, Sliders, and Steppers
    1. User Input and Output
      1. Sliders
      2. Steppers
      3. Image Views
      4. Visual Effect Views
    2. Creating and Managing Image Animations, Sliders, and Steppers
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlets and Actions
      5. Implementing the Application Logic
      6. Building the Application
    3. Further Exploration
    4. Summary
    5. Q&A
    6. Workshop
      1. Quiz
      2. Answers
    7. Activities
  20. Hour 9. Using Advanced Interface Objects and Views
    1. User Input and Output (Continued)
      1. Switches
      2. Segmented Controls
      3. Web Views
      4. Scrolling Views
      5. Stack Views
    2. Using Switches, Segmented Controls, and Web Views
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlets and Actions
      5. Implementing the Application Logic
      6. Building the Application
    3. Using Scrolling and Stack Views
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlets and Actions
      5. Implementing the Application Logic
      6. Building the Application
    4. Further Exploration
    5. Summary
    6. Q&A
    7. Workshop
      1. Quiz
      2. Answers
    8. Activities
  21. Hour 10. Getting the User’s Attention
    1. Alerting the User
      1. Alert Controllers
      2. System Sound Services
    2. Exploring User Alert Methods
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlets and Actions
      5. Implementing Alerts
      6. Implementing Action Sheets
      7. Implementing Alert Sounds and Vibrations
    3. Further Exploration
    4. Summary
    5. Q&A
    6. Workshop
      1. Quiz
      2. Answers
    7. Activities
  22. Hour 11. Implementing Multiple Scenes and Popovers
    1. Introducing Multiscene Storyboards
      1. The Terminology
      2. Preparing a Multiscene Project
      3. Adding Supporting View Controller Subclasses
      4. Creating a Segue
      5. Configuring Modal Segues
      6. Configuring the Popover Segue
      7. Presenting Modal Segues Manually
      8. Using Exits (and the Unwind Segue)
      9. Programming a Segue from Scratch
      10. Popover Peculiarities
      11. Passing Data Between Scenes
    2. Using Segues
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating the Modal Segue
      5. Unwinding Back to the Initial Scene
      6. Creating and Connecting the Outlets and Actions
      7. Implementing the Application Logic
      8. Building the Application
    3. Popovers, Universal Applications, and iPhones
      1. Configuring the Popover Segue
      2. Toggling to a Universal Application
    4. Further Exploration
    5. Summary
    6. Q&A
    7. Workshop
      1. Quiz
      2. Answers
    8. Activities
  23. Hour 12. Making Choices with Toolbars and Pickers
    1. Understanding the Role of Toolbars
      1. Bar Button Items
    2. Exploring Pickers
      1. Date Pickers
      2. Picker Views
    3. Using the Date Picker
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating the Segue
      5. Creating and Connecting the Outlets and Actions
      6. Implementing the Date Calculation Logic
      7. Implementing the Scene Segue Logic
      8. Building the Application
    4. Using a Custom Picker
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating the Segue
      5. Creating and Connecting the Outlets and Actions
      6. Implementing the Custom Picker View
      7. Implementing the Scene Segue Logic
      8. Building the Application
    5. Further Exploration
    6. Summary
    7. Q&A
    8. Workshop
      1. Quiz
      2. Answers
    9. Activities
  24. Hour 13. Advanced Storyboards Using Navigation and Tab Bar Controllers
    1. Advanced View Controllers
      1. Multiscene Development
    2. Exploring Navigation Controllers
      1. Navigation Bars, Items, and Bar Button Items
      2. Using Navigation Controllers in Storyboard
      3. Sharing Data Between Navigation Scenes
    3. Understanding Tab Bar Controllers
      1. Tab Bars and Tab Bar Items
      2. Using Tab Bar Controllers in Storyboard
      3. Sharing Data Between Tab Bar Scenes
    4. Using a Navigation Controller
      1. Implementation Overview
      2. Setting Up the Project
      3. Creating the Show Segues
      4. Designing the Interface
      5. Creating and Connecting the Outlets and Actions
      6. Implementing the Application Logic
      7. Building the Application
    5. Using a Tab Bar Controller
      1. Implementation Overview
      2. Setting Up the Project
      3. Creating the Tab Bar Relationships
      4. Designing the Interface
      5. Creating and Connecting the Outlets and Actions
      6. Implementing the Application Logic
      7. Building the Application
    6. Further Exploration
    7. Summary
    8. Q&A
    9. Workshop
      1. Quiz
      2. Answers
    10. Activities
  25. Hour 14. Navigating Information Using Table Views and Split View Controllers
    1. Understanding Tables
      1. Table Appearance
      2. Table Cells
      3. Adding a Table View
    2. Exploring the Split View Controller
      1. Implementing the Split View Controller
      2. The Master-Detail Application Template
    3. A Simple Table View Application
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Connecting the Delegate and Data Source Outlets
      5. Implementing the Application Logic
      6. Building the Application
    4. Creating a Master-Detail Application
      1. Implementation Overview
      2. Setting Up the Project
      3. Tweaking the Interface
      4. Implementing the Application Data Source
      5. Implementing the Master View Controller
      6. Implementing the Detail View Controller
      7. Building the Application
    5. Further Exploration
    6. Summary
    7. Q&A
    8. Workshop
      1. Quiz
      2. Answers
    9. Activities
  26. Hour 15. Reading and Writing Application Data
    1. iOS Applications and Data Storage
    2. Data Storage Approaches
      1. User Defaults
      2. Settings Bundles
      3. Direct File System Access
    3. Creating Implicit Preferences
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlets and Actions
      5. Implementing the Application Logic
      6. Building the Application
    4. Implementing System Settings
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlets
      5. Creating the Settings Bundle
      6. Implementing the Application Logic
      7. Building the Application
    5. Implementing File System Storage
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlets and Actions
      5. Implementing the Application Logic
    6. Further Exploration
    7. Summary
    8. Q&A
    9. Workshop
      1. Quiz
      2. Answers
    10. Activities
  27. Hour 16. Building Responsive User Interfaces
    1. Responsive Interfaces
      1. Enabling Interface Orientation Changes
      2. Designing Rotatable and Resizable Interfaces
    2. Using Auto Layout
      1. The Language and Tools of Auto Layout
      2. Navigating the Constraints Objects
      3. Manually Defining Constraints
      4. Example One: Centering Constraints
      5. Example Two: Expanding Controls
      6. Example Three: Variable and Matching Sizes
    3. Programmatically Defined Interfaces
      1. Implementation Overview
      2. Setting Up the Project
      3. Programming the Interface
      4. Building the Application
    4. Further Exploration
    5. Summary
    6. Q&A
    7. Workshop
      1. Quiz
      2. Answers
    8. Activities
  28. Hour 17. Using Advanced Touches and Gestures
    1. Multitouch Gesture Recognition
      1. Adding Gesture Recognizers
    2. 3D Touch Peek and Pop
      1. Adding 3D Touch Peek and Pop
    3. Using Gesture Recognizers
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Adding Gesture Recognizers to Views
      5. Creating and Connecting the Outlets and Actions
      6. Implementing the Application Logic
      7. Building the Application
    4. Implementing 3D Touch Gestures
      1. Implementation Overview
      2. Modifying ModalEditor
      3. Modifying FlowerDetail
    5. Further Exploration
    6. Summary
    7. Q&A
    8. Workshop
      1. Quiz
      2. Answers
    9. Activities
  29. Hour 18. Sensing Orientation and Motion
    1. Understanding Motion Hardware
      1. Accelerometer
      2. Gyroscope
    2. Accessing Orientation and Motion Data
      1. Requesting Orientation Notifications Through UIDevice
      2. Reading Acceleration, Rotation, and Attitude with Core Motion
    3. Sensing Orientation
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlet
      5. Implementing the Application Logic
      6. Building the Application
    4. Detecting Acceleration, Tilt, and Rotation
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlets and Actions
      5. Implementing the Application Logic
      6. Building the Application
    5. Further Exploration
    6. Summary
    7. Q&A
    8. Workshop
      1. Quiz
      2. Answers
    9. Activities
  30. Hour 19. Working with Rich Media
    1. Exploring Rich Media
      1. Media Player Framework
      2. AV Foundation and AV Kit Frameworks
      3. The Image Picker
      4. The Core Image Framework
    2. The Media Playground Application
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlets and Actions
      5. Implementing the Video Player
      6. Implementing Audio Recording and Playback
      7. Implementing the Photo Library and Camera
      8. Implementing a Core Image Filter
      9. Accessing and Playing the Music Library
    3. Further Exploration
    4. Summary
    5. Q&A
    6. Workshop
      1. Quiz
      2. Answers
    7. Activities
  31. Hour 20. Interacting with Other iOS Services
    1. Extending iOS Service Integration
      1. Contacts
      2. Email Messages
      3. Posting to Social Networking Sites
      4. Accessing the Safari Web Browser
      5. Mapping
    2. Using Contacts, Email, Social Networking, Safari, and Maps
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlets and Actions
      5. Implementing the Contacts Logic
      6. Implementing the Map Logic
      7. Implementing the Email Logic
      8. Implementing the Social Networking Logic
      9. Implementing the Safari View Controller
      10. Setting the Status Bar to White (Optional)
    3. Further Exploration
    4. Summary
    5. Q&A
    6. Workshop
      1. Quiz
      2. Answers
    7. Activities
  32. Hour 21. Implementing Location Services
    1. Understanding Core Location
      1. Getting Locations
      2. Getting Headings
    2. Creating a Location-Aware Application
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the View
      4. Creating and Connecting the Outlets
      5. Implementing the Application Logic
      6. Building the Application
    3. Using the Magnetic Compass
      1. Implementation Overview
      2. Setting Up the Project
      3. Updating the User Interface
      4. Creating and Connecting the Outlet
      5. Updating the Application Logic
      6. Building the Application
    4. Further Exploration
    5. Summary
    6. Q&A
    7. Workshop
      1. Quiz
      2. Answers
    8. Activities
  33. Hour 22. Building Background-Ready Applications
    1. Understanding iOS Backgrounding
      1. Types of Backgrounding
      2. Background-Aware Application Life Cycle Methods
    2. Disabling Backgrounding
    3. Handling Background Suspension
    4. Implementing Local Notifications
      1. Requesting Authorization for Notifications
      2. Common Notification Properties
      3. Creating and Scheduling a Notification
    5. Using Task-Specific Background Processing
      1. Preparing the Cupertino Application for Audio
      2. Implementing the Cupertino Audio Directions
      3. Adding the Background Modes
    6. Completing a Long-Running Background Task
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlet
      5. Implementing the Application Logic
      6. Enabling the Background Task Processing
      7. Building the Application
    7. Performing a Background Fetch
      1. Implementation Overview
      2. Setting Up the Project
      3. Designing the Interface
      4. Creating and Connecting the Outlet
      5. Implementing the Application Logic
      6. Adding the Background Fetch Mode
      7. Building the Application
    8. Adding 3D Touch Quick Actions
      1. Adding the Quick Action Icons
      2. Adding the Quick Action Definitions
      3. Implementing the Quick Action Logic
      4. Building the Application
    9. Further Exploration
    10. Summary
    11. Q&A
    12. Workshop
      1. Quiz
      2. Answers
    13. Activities
  34. Hour 23. Universal Applications and Size Classes
    1. Universal Application Development
      1. Configuring a Project as Universal
      2. Universal Tools and Techniques
    2. Size Classes
      1. Using the Size Class Tools
      2. Creating a Storyboard with Size Classes
    3. Further Exploration
    4. Summary
    5. Q&A
    6. Workshop
      1. Quiz
      2. Answers
    7. Activities
  35. Hour 24. Application Tracing, Monitoring, and Debugging
    1. Instant Feedback with NSLog
      1. Using NSLog
      2. Viewing NSLog Output
    2. Using the Xcode Debugger
      1. Setting Breakpoints and Stepping Through Code
    3. Further Exploration
    4. Summary
    5. Q&A
    6. Workshop
      1. Quiz
      2. Answers
    7. Activities
  36. Index
  37. Appendix A. Introducing Xcode Source Control
    1. A Brief Introduction to Source Control Systems
      1. Repositories and Working Copies
      2. Committing Changes
      3. Downloading Changes
      4. Branching and Merging
    2. Working with Subversion and Git Repositories
      1. Creating Local Git Repositories
      2. Connecting to Remote Repositories
      3. Checking Out a Working Copy
    3. Managing a Project in Source Control
      1. Status Codes
      2. Commits and Pushes
      3. Updates and Pulls
      4. Viewing Revisions
      5. Branches and Merges
    4. Accessing the Teach Yourself iOS 9 Tutorials Through Subversion
    5. Summary
  38. Code Snippets