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

Code Samples

In Learning Swift, 3rd Edition, you create Selfiegram, an app that makes use of several features of iOS, including working with the file system, capturing photos, and performing image analysis with the Vision framework.

We provide a code repository that contains the source code used in the book, as well as the playground that contains the general explanation of Swift that appears in Part 1 of the book.

Errata

If you have found an error, or otherwise have a suggestion for the book, please submit it via the O'Reilly errata system. Confirmed errata will also be listed below. eBook copies (and Safari) will be updated periodically to address confirmed errata, so you may not see these issues if you are looking at a copy of this book after April 2018.


Chapter 6 (“Building the Selfie List UI”) on page 152

The following line: 

"all we are doing now is using two more elements of the table view cell, subtitle and imageView”.

Should instead read: 

"all we are doing now is using two more elements of the table view cell, detailTextLabel and imageView”.


Chapter 6 (“Building the Selfie List UI”), page 145

The following lines: 

"The UITableViewController is the other object we’ll be using a lot to make our UI. It is a subclass of UITableViewController and is designed to control a table view”.

Should instead read: 

"The UITableViewController is the other object we’ll be using a lot to make our UI. It is a subclass of UIViewController and is designed to control a table view”. 


Chapter 9 (“Adding Location Info to the Selfies”), on page 178:

The following line of code:

let newImage = createImage(text: "ߐߐ

Should instead read:

let newImage = createImage(text: "😀”)

Chapter 10 ("Building a Settings View”), page 193

Insert the following two points after the first item in the list:

"2. Select the selfie list view controller.

3. In the Attributes inspector, change its Back Button property to "Back". This string is used in the navigation bar for any button that returns the user to this view controller."


Chapter 12 (“Theming and Sharing Selfiegram”), page 222:

The following dot point:

"3. Drag a button into the righthand side of the navigation bar."

Should instead read:

"3. Drag a UIBarButtonItem from the objects library into the right-hand side of the navigation bar. Be sure to drag it onto the bar itself, and not the area below the bar. If you make a mistake, you can just hit Command-Z."


Chapter 13 (“Custom Views and View Controllers”), on page 230:

The following line of code:

override func layoutSubviews() {
    previewLayer?.frame = self.bounds
}
override func viewWillLayoutSubviews() {
    self.cameraPreview?.setCameraOrientation(currentVideoOrientation)
}

Should instead read:

override func layoutSubviews() {
    previewLayer?.frame = self.bounds
}

Chapter 13 (“Custom Views and View Controllers”), on page 231:

The following lines:

"Our first step will be configuring a few properties for later use:

1. Create a completion handler property:"

Should instead read:

"We'll now start updating our CaptureViewController, and our first step will be configuring a few properties for later use:

1. Create a completion handler property in the CaptureViewController class:"


Chapter 13 ("Custom Views and View Controllers”), page 231:

The following line:

"5. Drag an empty UIView into the main view of the new navigation controller."

Should instead read:

"5. Drag an empty UIView into the main view of the view controller you just connected to the navigation controller."


Chapter 13 (“Custom Views and View Controllers”), page 234:

The following line:

"5. Control-drag from the cancel button into the CaptureViewController class and create a new action called takeSelfie."

Should instead read:

"5. Control-drag from the tap gesture recognizer into the CaptureViewController class and create a new action called takeSelfie."


Chapter 13 (“Custom Views and View Controllers”), on page 237:

The following lines of code:

override func layoutSubviews() {
    previewLayer?.frame = self.bounds
}

override func viewWillLayoutSubviews() {
    self.cameraPreview?.setCameraOrientation(currentVideoOrientation)
}

Should instead read:

override func viewWillLayoutSubviews() {
    self.cameraPreview?.setCameraOrientation(currentVideoOrientation)
}