Learning Cocoa with Objective-C, 4th Edition

Book description

Get up to speed on Cocoa and Objective-C, and start developing applications on the iOS and OS X platforms. If you don’t have experience with Apple’s developer tools, no problem! From object-oriented programming to storing app data in iCloud, the fourth edition of this book covers everything you need to build apps for the iPhone, iPad, and Mac.

You’ll learn how to work with the Xcode IDE, Objective-C’s Foundation library, and other developer tools such as Event Kit framework and Core Animation. Along the way, you’ll build example projects, including a simple Objective-C application, a custom view, a simple video player application, and an app that displays calendar events for the user.

  • Learn the application lifecycle on OS X and iOS
  • Work with the user-interface system in Cocoa and Cocoa Touch
  • Use AV Foundation to display video and audio
  • Build apps that let users create, edit, and work with documents
  • Store data locally with the file system, or on the network with iCloud
  • Display lists or collections of data with table views and collection views
  • Interact with the outside world with Core Location and Core Motion
  • Use blocks and operation queues for multiprocessing

Table of contents

  1. Preface
    1. Audience
    2. Organization of This Book
    3. Conventions Used in This Book
    4. Using Code Examples
    5. Safari® Books Online
    6. How to Contact Us
    7. Acknowledgments
  2. 1. Cocoa Development Tools
    1. The Mac and iOS Developer Programs
      1. Registering for a Developer Program
      2. Downloading Xcode from Apple Developer
    2. Getting Around in Xcode
      1. Creating Your First Cocoa Project
      2. The Xcode Interface
        1. The editor
        2. The toolbar
        3. The navigator
        4. Utilities
        5. The debug area
    3. Developing a Simple Objective-C Application
      1. Designing the Interface
      2. Connecting the Code
    4. Using the iOS Simulator
  3. 2. Object-Oriented Programming with Objective-C
    1. Object-Oriented Programming
      1. Objects
      2. Inheritance
      3. Interfaces and Implementations
      4. Methods
      5. Messages
      6. Properties
      7. Protocols
      8. Class Extensions
      9. Modules
    2. Memory Management
      1. Reference Counting
      2. Automatic Reference Counting
      3. Object Graphs in Objective-C
    3. The NSObject Lifecycle
      1. Allocation and Initialization
      2. Retain and Release
      3. Finalization and Deallocation
  4. 3. Foundation
    1. Mutable and Immutable Objects
    2. Strings
      1. Creating Strings
      2. Working with Strings
        1. Capitalization and working with paths
        2. Finding substrings
      3. Comparing Strings
      4. Searching Strings
    3. Arrays
      1. Fast Enumeration
      2. Mutable Arrays
    4. Dictionaries
    5. NSValue and NSNumber
    6. Data
      1. Loading Data from Files and URLs
      2. Serialization and Deserialization
    7. Design Patterns in Cocoa
      1. Model-View-Controller
      2. Delegation
      3. Key-Value Observing
  5. 4. Applications on OS X and iOS
    1. What Is an Application?
      1. Applications, Frameworks, Utilities, and More
      2. What Are Apps Composed Of?
      3. Using NSBundle to Find Resources in Applications
    2. The Application Lifecycle
      1. OS X Applications
      2. iOS Applications
        1. Multitasking on iOS
    3. The Application Sandbox
      1. Application Restrictions
        1. iOS application restrictions
        2. Mac application restrictions
        3. Private APIs
  6. 5. Graphical User Interfaces
    1. Interfaces in OS X and iOS
    2. MVC and Application Design
    3. Nib Files
      1. Structure of a Nib File
      2. Storyboards
      3. Outlets and Actions
      4. How Nib Files Are Loaded
    4. Constructing an Interface
      1. Guidelines and Constraints
    5. Building an App with Nibs and Constraints
    6. UI Dynamics
      1. UI and Gravity
      2. Snapping UI
    7. Designing Interfaces for Both iOS 6 and 7
    8. Core Animation
      1. Layers
      2. Animations
        1. Animations on OS X
        2. Animations on iOS
  7. 6. Blocks and Operation Queues
    1. Blocks
      1. Block Syntax
      2. Block Lifecycles
      3. Methods with Block Parameters
      4. Blocks and Memory Management
      5. Modifying Local Variables from Inside Blocks with __block
    2. Concurrency with Operation Queues
      1. Operation Queues and NSOperation
      2. Performing Work on Operation Queues
    3. Putting It All Together
  8. 7. Drawing Graphics in Views
    1. How Drawing Works
    2. The Pixel Grid
      1. Retina Displays
      2. Pixels and Screen Points
    3. Drawing in Views
      1. Frame Rectangles
      2. Bounds Rectangles
    4. Building a Custom View
      1. Creating the Project
      2. Filling with a Solid Color
      3. Working with Paths
      4. Creating Custom Paths
      5. Multiple Subpaths
      6. Shadows
        1. Saving and restoring graphics contexts
        2. Drawing a shadow
        3. Drawing shadows on iOS
      7. Gradients
        1. Drawing gradients on iOS
      8. Transforms
    5. SpriteKit
  9. 8. Audio and Video
    1. AV Foundation
    2. Playing Video with AVPlayer
      1. AVPlayerLayer
      2. Putting It Together
      3. AVPlayerView
    3. Playing Sound with AVAudioPlayer
    4. Speech Synthesis
    5. Working with the Photo Library
      1. Capturing Photos and Video from the Camera
      2. Building a Photo Application
      3. The Photo Library
  10. 9. Model Objects and Data Storage
    1. Key-Value Coding
    2. Key-Value Observing
      1. Registering for Change Notifications
      2. Notifying Observers of Changes
    3. Notifications with NSNotification
    4. Preferences
      1. Registering Default Preferences
      2. Accessing Preferences
      3. Setting Preferences
    5. Working with the Filesystem
      1. Using NSFileManager
        1. Creating directories
        2. Creating files
        3. Removing files
        4. Moving and copying files
      2. File Storage Locations
    6. Working with the Sandbox
      1. Enabling Sandboxing
      2. Open and Save Panels
      3. Security-Scoped Bookmarks
  11. 10. Cocoa Bindings
    1. Binding Views to Models
    2. A Single Bindings App
    3. Binding to Controllers
    4. Array and Object Controllers
    5. A More Complex Bindings App
  12. 11. Table Views and Collection Views
    1. Data Sources and Delegates
    2. Table Views
    3. UITableView on iOS
      1. Sections and Rows
      2. Table View Controllers
      3. Table View Cells
        1. Cell reuse
        2. Anatomy of a UITableViewCell
        3. Preparing table views in Interface Builder
        4. Analyzing tableView:cellForRowAtIndexPath:
        5. Responding to actions
      4. Implementing a Table View
    4. NSTableView on OS X
      1. Sorting a Table View
      2. NSTableView with Bindings
    5. Collection Views
      1. UICollectionView on iOS
  13. 12. Document-Based Applications
    1. The NSDocument and UIDocument Classes
    2. Document Objects in MVC
    3. Kinds of Documents
    4. The Role of Documents
    5. Document-Based Applications on OS X
      1. Autosaving and Versions
      2. Representing Documents with NSDocument
      3. Saving Simple Data
      4. Saving More Complex Data
    6. Document-Based Applications on iOS
  14. 13. Networking
    1. Connections
      1. NSURL
      2. NSURLRequest
      3. NSURLConnection
      4. NSURLSession
      5. NSURLResponse and NSHTTPURLResponse
    2. Building a Networked Application
    3. Bonjour Service Discovery
      1. Browsing for Shared iTunes Libraries
    4. Multipeer Connectivity
  15. 14. Working with the Real World
    1. Working with Location
      1. Location Hardware
        1. GPS
        2. WiFi base station lookups
        3. Cell tower lookups
        4. iBeacons
      2. The Core Location Framework
      3. Working with Core Location
    2. Geocoding
    3. Region Monitoring and iBeacons
    4. Locations and Privacy
    5. Maps
      1. Using Maps
      2. Annotating Maps
      3. Maps and Overlays
    6. Device Motion
      1. Working with Core Motion
    7. Printing Documents
      1. Printing on OS X
      2. Printing on iOS
    8. Game Controllers
    9. App Nap
  16. 15. Event Kit
    1. Understanding Events
      1. Accessing the Event Store
      2. Accessing Calendars
      3. Accessing Events
    2. Working with Events
    3. Building an Events Application
    4. User Privacy
  17. 16. Instruments and the Debugger
    1. Getting Started with Instruments
      1. The Instruments Interface
      2. Observing Data
      3. Adding Instruments from the Library
    2. Fixing Problems with Instruments
    3. Retain Cycles and Leaks
    4. Using the Debugger
      1. Setting Breakpoints
        1. Controlling program flow
        2. Custom breakpoints
        3. Special breakpoints
      2. Inspecting Memory Contents
      3. Working with the Debugger Console
  18. 17. Sharing and Notifications
    1. Sharing
      1. Sharing on iOS
      2. Sharing on OS X
    2. Notifications
      1. Push Notifications
        1. What happens when a push arrives
      2. Sending Push Notifications
      3. Setting Up to Receive Push Notifications
      4. Receiving Push Notifications
      5. Local Notifications
  19. 18. Nonstandard Apps
    1. Command-Line Tools
    2. Preference Panes
      1. How Preference Panes Work
      2. Preference Domains
      3. Building a Sample Preference Pane
    3. Status Bar Items
      1. Building a Status Bar App
    4. iOS Apps with Multiple Windows
  20. 19. Working with Text
    1. Internationalization and Localization
      1. Strings Files
      2. Creating a Sample Localized Application
    2. Formatting Data with NSFormatter
    3. Detecting Data with NSDataDetector
    4. TextKit
  21. 20. iCloud
    1. What iCloud Stores
    2. Setting Up for iCloud
    3. Testing Whether iCloud Works
    4. Storing Settings
    5. iCloud Storage
  22. Index
  23. Colophon
  24. Copyright

Product information

  • Title: Learning Cocoa with Objective-C, 4th Edition
  • Author(s): Paris Buttfield-Addison, Jonathon Manning, Tim Nugent
  • Release date: February 2014
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491901786