iOS Development with Swift
Craig Grummitt
  • November 2017
  • ISBN 9781617294075
  • 568 pages
  • printed in black & white
pBook available Nov 20, 2017
ePub + Kindle available Nov 30, 2017

A practical approach, with lots of real-world examples.

Andrea Prearo, Capital One

iOS Development with Swift is a hands-on guide to creating apps for iPhone and iPad using the Swift language. Inside, you'll be guided through every step of the process for building an app, from first idea to App Store. This book fully covers Swift 4, Xcode 9, and iOS 11.

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

8.3.4. Extracting keyboard information from the notification

8.4. Animating views

8.4.1. Animating the view from under the keyboard

8.4.2. Diving deeper into animating views with a sample bar chart

8.5. Scroll Views

8.5.1. Scroll view with form content and keyboard

8.5.2. Diving deeper into scroll views with image content

8.6. 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. Using large files

9.5. Deleting a row

9.6. 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. Local 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. Examining the data

14.8. Parsing JSON data with JSONSerialization

14.9. Parsing JSON data with JSONDecoder

14.10. Parsing JSON data with SwiftyJSON

14.10.1. Integrating SwiftyJSON with Carthage

14.10.2. Using SwiftyJSON

14.11. Downloading data from a web service

14.11.1. Accessing insecure domains

14.12. Displaying network activity indicator

14.13. Cancelling a task

14.14. 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

About the Technology

One billion iPhone users are waiting for the next amazing app. It's time for you to build it! Apple's Swift language makes iOS development easier than ever, offering modern language features, seamless integration with all iOS libraries, and the top-notch Xcode development environment. And with this book, you'll get started fast.

About the book

iOS Development with Swift is a hands-on guide to creating iOS apps. It takes you through the experience of building an app—from idea to App Store. After setting up your dev environment, you'll learn the basics by experimenting in Swift playgrounds. Then you'll build a simple app layout, adding features like animations and UI widgets. Along the way, you'll retrieve, format, and display data; interact with the camera and other device features; and touch on cloud and networking basics.

What's inside

  • Create adaptive layouts
  • Store and manage data
  • Learn to write and debug Swift code
  • Publish to the App Store
  • Covers Swift 4, Xcode 9, and iOS 11

About the reader

Written for intermediate web or mobile developers. No prior experience with Swift assumed.

About the author

Craig Grummitt is a successful developer, instructor, and mentor. His iOS apps have had over 100,000 downloads combined!

combo $49.99 pBook + eBook + liveBook
eBook $39.99 pdf + ePub + kindle + liveBook

FREE domestic shipping on three or more pBooks

More than just a guide to learning Swift, this book demonstrates concepts useful for any language.

Becky Huett, Big Shovel Labs

A self-contained step-by-step tutorial with plenty of examples.

Ghita Kouadri, University College London

Provides comprehensive knowledge of Swift 4 combined with clear explanations of iOS key concepts and APIs.

Zarko Jovicic, Quandoo Berlin