Learning Swift

Book description

Get hands-on experience with Apple’s Swift programming language by building real working apps. With this practical guide, skilled programmers with little or no knowledge of Apple development will learn how to code with Swift 2 by developing three complete, tightly linked versions of the Notes application for the OS X, iOS, and watchOS platforms.

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Resources Used in This Book
    2. Audience and Approach
    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. I. Swift Basics
  3. 1. Getting Started
    1. The Apple Developer Program
      1. Registering for the Apple Developer Program
      2. Downloading Xcode
    2. Creating Your First Project with Xcode
      1. The Xcode Interface
    3. Developing a Simple Swift Application
      1. Designing the Interface
      2. Connecting the Code
    4. Using the iOS Simulator
    5. Conclusion
  4. 2. The Basics of Swift
    1. The Swift Programming Language
      1. Swift 1 Versus Swift 2
    2. Playgrounds
    3. Comments
    4. Control Flow
      1. Loops
      2. Switches
    5. Variables and Constants
    6. Operators
    7. Types
    8. Working with Strings
      1. Comparing Strings
      2. Searching Strings
      3. Optional Types
      4. Type Casting
      5. Tuples
      6. Arrays
      7. Dictionaries
      8. Enumerations
      9. Sets
    9. Functions and Closures
      1. Using Functions as Variables
      2. Closures
      3. The defer Keyword
      4. The guard Keyword
    10. Conclusion
  5. 3. Swift for Object-Oriented App Development
    1. Classes and Objects
      1. Initialization and Deinitialization
      2. Properties
      3. Inheritance
      4. Protocols
      5. Extensions
      6. Access Control
      7. Operator Overloading
      8. Generics
      9. Subscripts
    2. Structures
    3. Modules
    4. The Swift Standard Library, Foundation, Cocoa, and Cocoa Touch
    5. Data
      1. Loading Data from Files and URLs
      2. Serialization and Deserialization
    6. Error Handling
    7. Memory Management
    8. Design Patterns in Cocoa and Cocoa Touch
      1. Model-View-Controller
      2. Delegation
    9. Structuring an App
      1. The Application Delegate
      2. Window Controllers and View Controllers
      3. Nibs and Storyboards
    10. Conclusion
  6. II. An OS X App
  7. 4. Setting Up the OS X Notes App
    1. Designing the OS X Notes App
    2. Creating the OS X Project
    3. Defining a Document Type
    4. Adding the Icon
    5. Conclusion
  8. 5. Working with Documents on OS X
    1. The NSDocument Class
    2. Storing Data in the Document
    3. Storing Text
      1. Package File Formats
      2. The guard Keyword, and Why It’s Great
      3. Saving Files
      4. Loading Files
    4. A Basic UI
    5. Conclusion
  9. 6. User Interfaces and iCloud
    1. Updating the UI
    2. Document-Filetype-Extension UI
      1. Getting an Icon for the Collection View Cells
      2. Adding Attachments
      3. Storing and Managing Attachments
      4. Displaying Data in the Collection View
    3. Enhancing Attachments
      1. Opening Attachments
      2. JSON Attachments
    4. Adding Attachments via Drag-and-Drop
      1. Adding QuickLook
    5. iCloud
    6. The Basics of iCloud
    7. Conclusion
  10. III. An iOS App
  11. 7. Setting Up the iOS Notes App
    1. Designing the iOS Notes App
    2. Creating the iOS Project
    3. Enabling the iOS App for iCloud
    4. Defining a Document Type
    5. Conclusion
  12. 8. Working with Files in iCloud
    1. The App Sandbox
    2. iCloud Availability
    3. Creating the Document List View Controller
      1. View Controllers and Storyboards
      2. The Navigation Controller
      3. Collection Views
      4. Using Constraints to Control Size and Position
    4. Creating the Document Class
    5. Listing Documents
    6. Creating Documents
    7. Downloading from iCloud
    8. Deleting Documents
    9. Renaming Documents
    10. Conclusion
  13. 9. Working with Documents on iOS
    1. Adding a View to Display Notes
    2. Editing and Saving Documents
    3. Conclusion
  14. 10. Working with Files and File Types
    1. Setting Up the Interface for Attachments
    2. Listing Attachments
      1. Determining Types of Attachments
      2. Displaying Attachment Cells
    3. Dealing with Conflicts
    4. Creating the Quick Look Thumbnail
    5. Conclusion
  15. 11. Images and Deletion
    1. Adding Attachments
    2. Adding Image Attachments
    3. Viewing Attachments
    4. Deleting Attachments
    5. Conclusion
  16. 12. Supporting the iOS Ecosystem
    1. Sharing with UIActivityController
    2. Handoffs
    3. Searchability
    4. Conclusion
  17. 13. Extending iOS Apps
    1. Searching with a Spotlight Indexing Extension
    2. Today Widgets
    3. Conclusion
  18. 14. Multimedia, Contacts, Location, and Notifications
    1. Location Attachments
    2. Audio Attachments
    3. Video Attachments
    4. Contact Attachments
    5. Notifications
    6. Conclusion
  19. 15. Polishing the iOS App
    1. Speaking Text
    2. Opening Links in SFSafariViewController
      1. 3D Touch
      2. Home Screen Quick Actions
      3. Peek and Pop
    3. Settings
    4. Undo Support
    5. Images with Filters
    6. Worldwide Apps
      1. Internationalization
      2. Localization
    7. Accessibility
    8. Splitscreen Multitasking
    9. Conclusion
  20. IV. Extending Your Apps
  21. 16. Building a watchOS App
    1. Designing for the Watch
    2. Designing Our watchOS App
    3. Creating the watchOS Extension
      1. Communicating with the iPhone
      2. User Interfaces for the Apple Watch
      3. Showing Note Contents
      4. Creating New Notes
      5. Adding Handoff Between the Watch and the iPhone
      6. Glances
    4. Conclusion
  22. 17. Code Quality and Distribution
    1. Debugging
    2. Instruments
    3. Testing
      1. Unit Testing
      2. UI Testing
    4. Using Objective-C and Swift in the Same Project
      1. Using Swift Objects in Objective-C
      2. Using Objective-C Objects in Swift
    5. The App Store
      1. App Thinning
      2. Testing iOS Apps with TestFlight
    6. Conclusion
  23. Index

Product information

  • Title: Learning Swift
  • Author(s): Paris Buttfield-Addison, Jon Manning, Tim Nugent
  • Release date: May 2016
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491940747