You are previewing Swift Development with Cocoa.
O'Reilly logo
Swift Development with Cocoa

Book Description

Ready to build apps for iPhone, iPad, and Mac now that Swift has landed? If you’re an experienced programmer who’s never touched Apple developer tools, this hands-on book shows you how to use the Swift language to make incredible iOS and OS X apps, using Cocoa and Cocoa Touch. You'll learn how to use Swift in a wide range of real-world situations, with Cocoa features such as Event Kit and Core Animation.

Table of Contents

  1. Preface
    1. Objective-C to Swift
    2. Audience
    3. Organization of This Book
    4. Conventions Used in This Book
    5. Using Code Examples
    6. Safari® Books Online
    7. How to Contact Us
    8. Acknowledgments
  2. 1. Cocoa Development Tools
    1. The Mac and iOS Developer Programs
      1. Registering for a Developer Program
      2. Downloading Xcode
    2. Creating Your First Project with Xcode
      1. The Xcode Interface
        1. The editor
        2. The toolbar
        3. The navigator
        4. Utilities
        5. The debug area
    3. Developing a Simple Swift Application
      1. Designing the Interface
      2. Connecting the Code
    4. Using the iOS Simulator
    5. Testing iOS Apps with TestFlight
  3. 2. Programming with Swift
    1. The Swift Programming Language
    2. Playgrounds
    3. Variables and Constants
    4. Types
      1. Tuples
      2. Arrays
      3. Dictionaries
    5. Control Flow
      1. Switches
    6. Functions and Closures
      1. Using Functions as Variables
      2. Closures
    7. Objects
      1. Inheritance
      2. Initialization and Deinitialization
      3. Properties
      4. Protocols
      5. Extensions
      6. Access Control
      7. Operators
      8. Generics
    8. Interoperating with Objective-C
    9. Using Objective-C and Swift in the Same Project
      1. Using Swift Objects in Objective-C
      2. Using Objective-C Objects in Swift
    10. Modules
    11. Memory Management
    12. Working with Strings
      1. Comparing Strings
      2. Searching Strings
    13. Data
      1. Loading Data from Files and URLs
      2. Serialization and Deserialization
    14. Design Patterns in Cocoa
      1. Model-View-Controller
      2. Delegation
  4. 3. 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 Life Cycle
      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
    4. Notifications with NSNotification
  5. 4. Graphical User Interfaces
    1. Interfaces in OS X and iOS
    2. MVC and Application Design
    3. Nib Files and Storyboards
      1. Structure of a Nib File
      2. Storyboards
      3. Outlets and Actions
      4. How Nib Files and Storyboards Are Loaded
    4. Constructing an Interface
      1. Guidelines and Constraints
    5. Building an App with Nibs and Constraints
    6. Interfaces on iOS
      1. Launch Screen Files
    7. UI Dynamics
      1. UI and Gravity
      2. Snapping UI
    8. Core Animation
      1. Layers
      2. Animations
        1. Animations on OS X
        2. Animations on iOS
  6. 5. Closures and Operation Queues
    1. Closures in Cocoa
    2. Concurrency with Operation Queues
    3. Operation Queues and NSOperation
    4. Performing Work on Operation Queues
    5. Putting It All Together
  7. 6. 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. Filling with a Solid Color
      2. Working with Paths
      3. Creating Custom Paths
      4. Multiple Subpaths
      5. Shadows
        1. Saving and restoring graphics contexts
        2. Drawing a shadow
        3. Drawing shadows on iOS
      6. Gradients
        1. Drawing gradients on iOS
      7. Transforms
  8. 7. SpriteKit
    1. SpriteKit’s Architecture
    2. Making an App That Uses SpriteKit
    3. Working with SpriteKit Scenes
    4. SpriteKit Nodes
    5. Putting Sprites in Scenes
    6. Responding to Touches
    7. Working with Textures
    8. Texture Atlases
    9. Working with Text
    10. Animating Content with Actions
    11. Using Shape Nodes
    12. Using Image Effect Nodes
    13. Adding Physics to SpriteKit Objects
    14. Adding Joints to SpriteKit Objects
    15. Lighting SpriteKit Scenes
    16. Constraints
    17. Using Shaders in SpriteKit
    18. Using SpriteKit Editor
  9. 8. SceneKit
    1. SceneKit Structure
    2. Working with SceneKit
    3. Adding a SceneKit View
    4. Adding a Scene
    5. Adding a Camera
    6. Adding a 3D Object
    7. Adding Lights
    8. Animating Content in the Scene
    9. Creating Text Geometry
      1. Combining Animations
    10. Working with Materials
      1. Normal Mapping
    11. Hit Testing
    12. Constraints
    13. Loading Data from COLLADA Files
    14. Adding Physics to the Scene
  10. 9. Audio and Video
    1. AV Foundation
    2. Playing Video with AVPlayer
      1. AVPlayerLayer
      2. Putting It Together
      3. AVKit
      4. AVKit on iOS
      5. Playing Sound with AVAudioPlayer
    3. Speech Synthesis
    4. Working with the Photo Library
      1. Capturing Photos and Video from the Camera
      2. Building a Photo Application
      3. The Photo Library
  11. 10. iCloud and Data Storage
    1. Preferences
      1. Registering Default Preferences
      2. Accessing Preferences
      3. Setting Preferences
    2. Working with the Filesystem
      1. Using NSFileManager
        1. Getting a temporary directory
        2. Creating directories
        3. Creating files
        4. Removing files
        5. Moving and copying files
      2. File Storage Locations
    3. Working with the Sandbox
      1. Enabling Sandboxing
      2. Open and Save Panels
      3. Security-Scoped Bookmarks
    4. iCloud
    5. What iCloud Stores
    6. Setting Up for iCloud
    7. Testing Whether iCloud Works
    8. Storing Settings
      1. Handling External Changes
      2. The iOS Counterpart
    9. iCloud Storage
      1. iCloud Storage on OS X
      2. iCloud Storage on iOS
    10. Document Pickers
    11. Using iCloud Well
  12. 11. Cocoa Bindings
    1. Binding Views to Models
    2. A Simple Bindings App
    3. Binding to Controllers
    4. Array and Object Controllers
    5. A More Complex Bindings App
  13. 12. Table Views and Collection Views
    1. Data Sources and Delegates
    2. Table Views
      1. 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
      2. NSTableView on OS X
        1. Sorting a Table View
        2. NSTableView with Bindings
    3. Collection Views
      1. UICollectionView on iOS
  14. 13. Document-Based Applications
    1. The NSDocument and UIDocument Classes
    2. Document Objects in MVC
      1. Kinds of Documents
      2. The Role of Documents
    3. Document-Based Applications on OS X
      1. Autosaving and Versions
      2. Representing Documents with NSDocument
      3. Saving Simple Data
      4. Saving More Complex Data
    4. Document-Based Applications on iOS
  15. 14. Networking
    1. Connections
      1. NSURL
      2. NSURLRequest
      3. NSURLSession
      4. NSURLResponse and NSHTTPURLResponse
    2. Building a Networked Application
    3. Bonjour Service Discovery
      1. Browsing for Shared iTunes Libraries
    4. Multipeer Connectivity
  16. 15. 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
      2. Using the Built-in Altimeter
      3. Using the Pedometer
    7. Printing Documents
      1. Printing on OS X
      2. Printing on iOS
    8. Game Controllers
    9. App Nap
    10. Authenticating Using Touch ID
    11. Handoff
  17. 16. EventKit
    1. Understanding Events
    2. Accessing the Event Store
    3. Accessing Calendars
    4. Accessing Events
    5. Working with Events
    6. Building an Events Application
    7. User Privacy
  18. 17. 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 Using 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
    5. View Debugging
    6. The Testing Framework
      1. Writing Tests
      2. Writing Asynchronous Tests
      3. Performance-Testing Blocks with Tests
    7. Debug Gauges
    8. Performance Optimization
  19. 18. Sharing and Notifications
    1. Sharing
    2. Sharing on iOS
    3. Sharing on OS X
    4. Notifications
      1. Registering Notification Settings
      2. Push Notifications
      3. What Happens When a Notification Arrives
    5. Sending Push Notifications
    6. Setting Up to Receive Push Notifications
    7. Receiving Push Notifications
    8. Local Notifications
  20. 19. 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
  21. 20. Working with Text
    1. Internationalization and Localization
      1. Strings Files
      2. Creating a Sample Localized Application
    2. Formatting Data with NSFormatter
      1. Testing Different Locales
    3. Formatting Numbers, Lengths, Mass, Energy, and Data
      1. NSNumberFormatter
      2. NSEnergyFormatter, NSMassFormatter, and NSLengthFormatter
      3. NSByteCountFormatter
    4. Detecting Data with NSDataDetector
    5. TextKit
  22. Index
  23. Colophon
  24. Copyright