O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learning Swift, 3rd Edition

Book Description

Get valuable hands-on experience with Swift, the open source programming language developed by Apple. With this practical guide, skilled programmers with little or no knowledge of Apple development will learn how to code with the latest version of Swift by developing a working iOS app from start to finish.

You’ll begin with Swift programming basics—including guidelines for making your code "Swifty"—and learn how to work with Xcode and its built-in Interface Builder. Then you’ll dive step-by-step into building and customizing a basic app for taking, editing, and deleting selfies. You’ll also tune and test the app for performance and manage the app’s presence in the App Store.

Divided into four parts, this book includes:

  • Swift 4 basics: Learn Swift’s basic building blocks and the features of object-oriented development
  • Building the Selfiegram app: Build model objects and the UI for your selfie app and add location support, user settings, and notifications
  • Polishing Selfiegram: Create a theme and support for sharing and add custom views, image overlays, and localization
  • Beyond app development: Debug and performance test with Xcode, automate chores with Fastlane, and user-test the app with TestFlight

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. O’Reilly Safari
    7. How to Contact Us
    8. Acknowledgments
  2. I. Welcome to Swift
  3. 1. Getting Started
    1. Xcode
      1. Getting Xcode
      2. Creating Your First Project
    2. Working with the Xcode Interface
      1. The Editor
      2. The Toolbar
      3. The Navigator
      4. Utilities
      5. The Debug Area
    3. Running Your Code
      1. The iOS Simulator
      2. Running on a Device
      3. Distributing Your Apps
    4. The Interface Builder
      1. Interfaces in iOS
    5. Conclusion
  4. 2. The Swift Programming Language
    1. The Swift Language
      1. Swift 3 Versus 4
    2. Playgrounds and Swift
    3. Comments
    4. Imports
    5. Variables
    6. Operators
    7. Collections
      1. Arrays
      2. Tuples
      3. Dictionaries
    8. Control Flow
      1. Loops
      2. Switches
    9. Types
      1. Working with Strings
      2. Sets
      3. Enumerations
      4. Type Safety and Conversion
      5. Optionals
      6. Type Casting
    10. Functions and Closures
      1. Using Functions as Variables
      2. Closures
    11. Convenience Features
      1. The defer Keyword
      2. The guard Keyword
    12. Making Your Code Swifty
    13. Conclusion
  5. 3. Object-Oriented Development in Swift
    1. Classes and Objects
      1. Initialization and Deinitialization
      2. Properties
      3. Inheritance
      4. Protocols
      5. Extensions
      6. Access Control
      7. Operator Overloading and Custom Operators
      8. Subscripts
      9. Generics
    2. Structures
    3. Error Handling
    4. Memory Management
    5. Design Patterns in Swift
      1. Model–View–Controller
      2. Delegation
    6. Swift Libraries
      1. Structuring an App
    7. Swift Package Manager
    8. Conclusion
  6. II. Building Selfiegram
  7. 4. Setting Up Our App
    1. Designing Selfiegram
    2. Creating the Project
    3. The Structure
    4. Renaming the Views
  8. 5. Building the Model Object
    1. The Selfie Object
    2. The SelfieStore
    3. Testing the SelfieStore
    4. Filling Out the Method Stubs
  9. 6. Building the Selfie List UI
    1. Creating the Selfie List
    2. Improving the Selfie List
  10. 7. Adding and Deleting Selfies
    1. Deleting Selfies
    2. Taking New Selfies
  11. 8. Viewing and Editing Selfies
    1. The Selfie Viewer
      1. Connecting the Code and the UI
    2. Editing a Selfie
  12. 9. Adding Location Info to the Selfies
    1. Updating the Model
    2. Testing Our New Model
    3. Showing a Selfie’s Location
    4. Expanding the Map
    5. Determining Locations
      1. Configuring the App to Support Location
      2. Talking to the Location Hardware
  13. 10. Building a Settings View
    1. Building the Settings UI
      1. Connecting the Settings into Our Hierarchy
      2. Hooking Up the Settings
    2. Implementing the Settings
  14. 11. Reminders and Notifications
    1. Adding a Reminder to the Settings
    2. Creating a Notification
  15. III. Polishing Selfiegram
  16. 12. Theming and Sharing Selfiegram
    1. Custom Fonts
    2. Making the Theme
    3. Sharing Selfies
      1. Sharing from the Detail View Controller
      2. Sharing from the List View Controller
  17. 13. Custom Views and View Controllers
    1. A Camera View
    2. The Camera View Controller
      1. Building the UI
      2. Connecting the UI
      3. Talking to the Camera
    3. Calling the Capture View Controller
  18. 14. Image Overlays
    1. Creating the Overlay Model
    2. Testing the Overlay Manager
      1. Writing the Tests
      2. Returning Available Overlays
      3. Downloading Overlay Information
      4. Downloading Overlay Images
  19. 15. Overlay UI
    1. Building the UI
      1. Hooking Up the UI
    2. Creating the Overlay View
    3. Presenting the Overlays
      1. Initial Setup
      2. Drawing Eyebrows
      3. Vision and Image Detection
    4. Connecting It into the App
  20. 16. Localization and Internationalization
    1. Internationalization
      1. Generating the String Table
    2. Localization
      1. Translating the Strings
    3. Testing Locales
      1. Pseudolanguages
      2. Previewing Localizations
    4. Conclusion
  21. IV. Beyond Developing Selfiegram
  22. 17. Debugging
    1. The Debugger
      1. Breakpoints
      2. Inspecting Code
      3. Controlling Program Flow
    2. Performance
      1. Instruments
  23. 18. UI Tests
    1. UI Testing Classes
    2. Writing UI Tests
      1. A Basic Test
      2. Recording UI Actions
      3. Checking if Elements Exist
      4. Handling UI Interruptions
  24. 19. Automating Chores with Fastlane
    1. The Fastlane Tools
    2. Installing Fastlane
      1. Installing via Homebrew
      2. Installing via RubyGems
      3. Installing via Direct Download
    3. Setting Up a Project
    4. Doing a Build
    5. Configuring a Fastfile
  25. 20. Using Fastlane’s Tools
    1. Code Signing with match
      1. The Problem That Match Solves
      2. match’s Solution
    2. Generating Screenshots Using snapshot
    3. Using Boarding to Add Testers to TestFlight
    4. Managing Your App’s Presence on the App Store Using deliver
      1. Getting the Metadata
      2. Submitting New Metadata
    5. Looking Further
  26. Index