iOS Development with Swift
Craig Grummitt
  • MEAP began July 2016
  • Publication in December 2017 (estimated)
  • ISBN 9781617294075
  • 550 pages (estimated)
  • printed in black & white


This book will be updated for Swift 4 when the beta is released. If you buy the eBook beforehand, you will be able to download the updated version at no additional charge as soon as it's ready.

First, the statistics. According to Apple, there are currently 380,000 registered iOS developers and over a billion iOS devices in use worldwide. Swift, the language of iOS development, is the fastest growing programming language, and the App Store has taken in more than $8 billion in sales. If you're a developer, learning how to write iPhone and iPad apps in Swift is a safe bet for job security. And because mobile app development is a rapidly-changing field that combines programming, UI design, and a bit of showmanship, it's also a great bet for job satisfaction. Ready to get started?

iOS Development with Swift is a hands-on guide to creating apps for iPhone and iPad using the Swift language. You'll start by getting a birds-eye view of how an iOS application works and what it takes to build one. Then, you'll get a quick tour of Swift that highlights its similarities and differences compared to other C-style languages. With the basics well in hand, you'll work through progressively more challenging examples as you learn how to design iOS apps, build good layouts, handle navigation, and interact with the device's camera. Along the way, you'll deepen your knowledge of iOS and the Swift language through a series of tips, sidebars, and exercises.

Table of Contents detailed table of contents

Part 1: Introducing Xcode and Swift

1. Your first iOS Application

1.1. Exploring iOS SDK

1.2. Creating an Xcode project

1.2.1. Templates

1.2.2. Project options

1.3. Exploring the Xcode interface

1.3.1. Toolbar area

1.3.2. Utility area

1.3.3. Navigator area

1.3.4. Editor area

1.3.5. Debug area

1.4. Editing your app’s interface

1.4.1. Storyboards and nibs

1.4.2. View controllers and views

1.4.3. Interface Builder

1.4.4. Object Library

1.4.5. Document Outline

1.4.6. Inspectors

1.5. Running your app

1.5.1. Running your app on a device

1.5.2. Running your app in the simulator

1.5.3. Running your app

1.5.4. Simulator features

1.6. Peeking at a completed app

1.6.1. Checking out a repository in Xcode

1.6.2. Peeking at the completed app’s storyboard

1.6.3. Tweaking the code

1.7. Summary

2. Introduction to Swift in the playground

2.1. Xcode playground

2.1.1. Results Sidebar

2.1.2. Automatic compiling

2.1.3. Console

2.2. Type safety and type inference

2.2.1. Converting numeric types

2.2.2. Concatenating strings

2.3. Collections

2.3.1. Arrays

2.3.2. Sets

2.3.3. Dictionaries

2.4. Control Flow

2.4.1. For-in

2.4.2. Switch statement

2.5. Functions

2.5.1. Modifying external parameter names

2.5.2. Omitting external parameter names

2.5.3. Default parameter names

2.6. Optionals

2.6.1. Declaring an optional

2.6.2. Unwrapping an optional

2.6.3. Optional chaining

2.6.4. Final comments on optionals

2.7. Tuples

2.7.1. Tuples as return values

2.7.2. Tuple magic

2.8. Higher-order functions

2.8.1. Map

2.8.2. Closures

2.8.3. Filter

2.8.4. Reduce

2.8.5. Sorted

2.9. Summary

3. Swift objects

3.1. Classes

3.1.1. Defining a class

3.1.2. Properties

3.1.3. Initializers

3.1.4. Methods

3.1.5. Computed properties

3.1.6. Class inheritance

3.1.7. Protocols

3.2. Structures

3.2.1. Structures vs classes

3.3. Extensions

3.3.1. Extensions of your type

3.3.2. Extensions of their type

3.3.3. Operator overloading

3.3.4. Generics

3.4. Summary

Part 2: Building your interface

4. View Controllers, Views and Outlets

4.1. View Hierarchy

4.1.1. The Window

4.2. Model-view-controller

4.3. View Controller

4.3.1. Creating a custom view controller

4.3.2. Customizing a UIViewController subclass

4.3.3. Initial View Controller

4.3.4. View Controller Life cycle

4.3.5. Container View Controllers

4.4. Managing Views

4.4.1. Managing views in code

4.4.2. Managing views in Interface Builder

4.5. Summary

5. User interaction

5.1. Controls

5.1.1. Buttons

5.1.2. Text field

5.1.3. Other controls

5.2. Touching views

5.2.1. Hit testing

5.2.2. Overriding touch methods

5.2.3. The responder chain

5.3. Gesture recognizers

5.3.1. Pan gesture

5.3.2. Pinch gesture

5.3.3. Rotate gesture

5.3.4. Simultaneous gesture recognizers

5.3.5. Tap gesture in code

5.4. Summary

6. Adaptive layout

6.1. The problem

6.2. Auto layout

6.2.1. Auto layout in Interface Builder

6.2.2. Auto layout in code

6.2.3. Auto layout tips

6.3. Autoresizing

6.3.1. Autoresizing in code

6.3.2. Autoresizing in Interface Builder

6.3.3. Autoresizing considerations

6.4. Manual Adaptive layout

6.4.1. Receiving transition events

6.4.2. Receiving layout events

6.5. Choosing an approach

6.6. Summary

7. More adaptive layout

7.1. Size classes

7.1.1. Size classes in code

7.1.2. Size classes in Interface Builder

7.2. Stack Views

7.2.1. The problem with auto layout

7.2.2. Stack view properties

7.2.3. Simple Stack view in Interface Builder

7.2.4. Nested stack views in Interface Builder

7.2.5. Adding or removing views from a stack view

7.2.6. Stack views in code

7.3. Summary

8. Keyboard notifications, animations, and scrolling

8.1. The problem with the keyboard

8.2. Dismissing the keyboard

8.2.1. Dismissing the keyboard by resigning the first responder!

8.2.2. Detecting when to dismiss the keyboard

8.3. Observing Keyboard Notifications

8.3.1. What is a notification?

8.3.2. Observing a keyboard frame change notification

8.3.3. Unregistering a notification

Extracting keyboard information from the notification === Animating views ==== Animating the view from under the keyboard ==== Diving deeper into animating views with a sample bar chart === Scroll Views ==== Scroll view with form content and keyboard ==== Diving deeper into scroll views with image content === Summary

Part 3: Building Your App

9. Tables and navigation

9.1. Displaying data in table views

9.1.1. Setting up a table view controller in the storyboard

9.1.2. Displaying data in the table view

9.2. Adding a row

9.2.1. Embedding in a Navigation Controller

9.2.2. Creating a segue

9.2.3. Embedding second navigation controller

9.2.4. Communicating with the books scene using your own delegate

9.2.5. Adding the data to the table

9.3. Editing a row

9.3.1. Creating a segue from a row

9.3.2. Passing in the book object to edit

9.3.3. Removing the view controller

9.3.4. Updating the book object

9.4. Deleting a row

9.5. Summary

10. Collections, searching, sorting and tab bars

10.1. Sorting the data

10.1.1. Creating a sort method to sort the book array.

10.1.2. Changing sort order

10.2. Searching the data

10.2.1. Creating a search controller

10.2.2. Filtering the data

10.2.3. Removing and updating rows with filtered data

10.3. Displaying data in collection views

10.3.1. Creating custom collection cells

10.3.2. Displaying data in a custom collection view cell

10.3.3. Implementing a flow layout

10.3.4. Adding a search bar to the collection view

10.3.5. Implementing the flow layout delegate

10.4. Creating sections with a Tab Bar Controller

10.4.1. Sharing data between tabs

10.5. Summary

11. Data persistence

11.1. Preserving User Preferences and State

11.1.1. Preserving and Restoring State

11.1.2. Preserving User Preferences on the Device

11.2. Storing data locally

11.2.1. Storage setup

11.2.2. Structured data files

11.2.3. Archiving objects

11.2.4. SQLite

11.2.5. Core Data

11.3. Summary

12. Data persistence in iCloud

12.1. Setting your app up for iCloud

12.2. Persisting Data with Ubiquitous Key-Value Store

12.3. Storing data using CloudKit

12.3.1. Updating the model for CloudKit

12.3.2. Adding a book record to CloudKit

12.3.3. Updating a book record in CloudKit

12.3.4. Loading book records in CloudKit

12.3.5. Deleting a book record in CloudKit

12.3.6. Managing CloudKit errors

12.3.7. Refreshing CloudKit data

12.3.8. Subscribing to changes

12.4. Summary

13. Graphics and media

13.1. Adding images to your app with an asset catalog

13.1.1. Adding image sets

13.1.2. Adding app icons

13.2. Displaying a launch screen

13.3. Drawing with Core Graphics

13.3.1. Overriding the draw method

13.3.2. Describing a path

13.3.3. Drawing into the graphics context

13.3.4. Saving and restoring graphics state

13.3.5. Drawing paths with UIBezierPath drawing methods

13.3.6. Rendering views in Interface Builder

13.3.7. Creating a star rating view

13.4. Drawing with Core Animation

13.5. Using the camera

13.5.1. Taking photos with the image picker controller

13.5.2. Selecting photos from Photo library with the image picker controller

13.5.3. Taking photos with AVFoundation

13.6. Playing sounds

13.7. Summary

14. Networking

14.1. Using a web service

14.2. Setting up a books service

14.3. Communicating with the web service

14.4. Creating a URL Session

14.4.1. URLSessionConfiguration

14.4.2. URLSession

14.5. Setting up the URL request

14.6. Requesting data from a web service

14.7. Parsing JSON data with JSONSerialization

14.8. Parsing JSON data with SwiftyJSON

14.8.1. Integrating SwiftyJSON with Carthage

14.8.2. Using SwiftyJSON

14.9. Downloading data from a web service

14.9.1. Accessing insecure domains

14.10. Displaying network activity indicator

14.11. Cancelling a task

14.12. Summary

15. Debugging and testing

15.1. The setup

15.2. Debugging mode

15.3. Debugging crash logs in the console

15.3.1. Solving a crash caused by an outlet

15.3.2. Solving a crash caused by an action

15.4. Examining variables and breakpoints

15.4.1. Examining a variable with print

15.4.2. Pausing your app with a breakpoint

15.4.3. Examining a variable with the variables view

15.4.4. Controlling the app’s execution using the debug bar

15.4.5. Examining a variable with quick look

15.4.6. Examining a variable with print description

15.4.7. Examining a variable with lldb

15.4.8. Examining a variable with datatips

15.4.9. Solving the save problem

15.4.10. Examining a variable in summary

15.5. Debugging playback with gauges and instruments

15.5.1. Debugging playback with debug gauges

15.5.2. Debugging playback with instruments

15.5.3. Solving the playback problem

15.6. Debugging the user interface

15.6.1. Debugging the user interface with the Debug View Hierarchy

15.6.2. Debugging the user interface with runtime issues

15.6.3. Solving the user interface problem

15.7. Testing your app

15.7.1. Testing for functionality

15.7.2. Testing for performance

15.7.3. Testing your user interface

15.8. Summary

Part 4: Finalizing your app

16. Distributing your app

16.1. Joining the Apple Developer Program

16.1.1. Signing into Xcode

16.1.2. Code signing your app

16.2. Setting up an App in iTunes Connect

16.3. Uploading your build to iTunes Connect

16.4. Distributing your app to beta testers

16.4.1. Distributing to beta testers manually

16.4.2. Distributing to beta testers with TestFlight

16.5. Distributing your app to the App Store

16.6. Summary

17. What’s next?

17.1. Further learning

17.2. One more thing!


Appendix A: Project Settings

Appendix B: Swift Syntax cheat sheets

What's inside

  • Introduction to mobile app development for iPhone and iPad
  • Adaptive designs that respond to different environments
  • Storing and managing data
  • Connecting to web services
  • Publishing to the App Store
  • Testing and debugging Swift code

About the reader

Written for readers with experience using a language like Java, Python, or C#. No prior iOS development or Swift experience required.

About the author

Craig Grummitt has been developing interactive applications for over 20 years, including touch-screen exhibits, Facebook games, online learning, and mobile apps. He's a successful online instructor and mentor, and his iOS apps have had over 50,000 downloads.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $49.99 pBook + eBook + liveBook
MEAP eBook $39.99 pdf + ePub + kindle + liveBook

FREE domestic shipping on three or more pBooks