A Better Way to Learn Swift

Introduction

No looking back now.

You've come to this tutorial because you want to learn Swift, Apple's new programming language for making iOS and MacOS apps. This tutorial is bringing together various resources to swiftly (ha!) and thoroughly introduce each component of the Swift Programming Language.

There was an initial frenzy of excitement around the new language in June when Apple introduced Swift at WWDC 2014. Since then, the various beta bugs and the fact that no devices supported apps built in Swift has led to a bit of a decline in Swift's popularity. Well Swift is now in release 1.0 and iOS8 will soon be in the hands of millions of developers and consumers alike. There has never been a better time to dive into Swift.

A note on this tutorial

Swift is in its infancy. This tutorial is going to evolve and change as we learn more about the language and the applications of the concepts we cover. We are also constantly looking for more and better resources for each topic. With that in mind, you can find the raw markdown for this tutorial over at Github. If you find good Swift resources that aren't mentioned here, feel free to submit a pull request!

We'd like to give a special thanks to the great folks over at Swiftcast for kick-starting this tutorial. If you have any questions or comments tweet them at @SwiftCastTV!

Prerequisites

To work through this tutorial you'll need a fully functioning Apple developer setup. This includes

Resources

We expect a plethora of learning resources to come out for Swift now that the language is out of beta. Luckily, many resources are already available and this heavily leverages the following (and they are all free!):

  • The Swift Programming Language ebook from Apple (also available on iBooks)
  • The MadApper Swift Video Series
  • The Skip Wilson Swift Video Series

One Last Thing

This entire tutorial can be done in a playground: an interactive environment that exists in xcode that allows you to code and receive immediate results from your code without having to compile an app. Before actually learning about Swift, learn how to create and navigate around playgrounds.

Swift Basics

Now you are going to dive into the language itself. The goal of this section is to get a handle on the syntax, operators, and data types in Swift.

Swift Syntax

When learning a new language syntax, it is recommended that you immediately start writing in the language as much as possible. Apple's "A Swift Tour" chapter of The Swift Programming Guide provides an overview of Swift Syntax as well as a set of "experiments", short exercises that let you write some Swift code focusing on a different aspect of the Swift Syntax.

Readings

Along with the experiments in the Swift ebook, we are including two blog posts about reserved words and operators that can serve as reference materials.

Swift Types

If you've made it this far you've read that one of the good parts about Swift is that it is a type-safe language. Even without having any idea what that means, you can probably assume the section in this tutorial about types is important. For learning about types, the MadApper video series and Apple's documentation pair nicely. Types in Swift can be confusing because there are four categories of types: named types, compound types, value types, and reference types. Each type in Swift is a compound type or a named type as well as either a reference type or a value type. Confused yet? No worries, we'll sort all of this out.

Pre-Readings

For Types, do the readings first before watching the videos on the specific types.

Videos

Extensions

We can take all of our knowledge of the various data types in Swift and give them new functionality. Extensions allow us to give types new methods to suit the needs of our applications. For this, watch a long and awesome video on creating an extension and don't forget only named types can be extended.

Readings

Control Flow

Okay now things get exciting. We are going to cover optionals, loops, functions, and closures. These concepts allow us to allow our code to do things only under certain conditions. Armed with this knowledge and what you've learned so far, you will be able to write code more concisely and you'll even be able to write the logic for basic games.

Loops and Conditionals

Control flow constructs in Swift allow us to iterate over collections, loop through a chunk of code multiple times, and execute code based on conditional statements. The MadApper series does a good job of covering these concepts

Optionals

Optional are a concept that is introduced in Swift and has no parallel in C or Objective-C. Using them effectively can prevent some common programming errors and increase the type safety of your code.

Readings

Functions and Closures

Functions and Closures are self-contained blocks of code functionality. That is a vague explanation because functions and closures have very broad uses and can take many forms. For this section, jump in with two long (and excellent) video tutorials from Skip Wilson to get a practical crash course.

Functions and closures can take many forms in Swift. The difference between a function and a closure can also be hard to grasp. The videos cover the basics, but these readings will give you a more complete understanding.

Object Oriented Programming

Objective-C is an object-oriented programming language. Swift preserves many of the object-oriented ideas and constructs from Objective-C and you'll need to be comfortable with these concepts to write apps in Swift.

Readings

Methods, Properties, and Initializers were covered in the videos, but the Swift ebook is a good place to get a detailed explanation of each of those ideas.

Now for a few practical readings on Swift objects

Testing

Testing is important to driving the design of our applications, ensuring they behave as we expect, and documenting our code.

Readings

Meet the Gang

There is an array of libraries to use for testing. Whether your flavor is BDD or just plain old TDD there is something for everyone!

  • Sleipinr is a BDD style testing framework for Swift.
  • Quick is another BDD style testing framework for Swift.
  • Nimble is a compliment to Quick. It's a Matchers framework.

SDK's

When it comes to actually building apps in Swift, it is paramount to get an understanding of the various SDKs provided by Apple to get a sense for all of deep functionality that Apple provides for developers and to prevent yourself from trying to write code for functionality that already exists in an SDK or library. In fact, we recommend always looking for a trusted library before embarking on writing your own functionality (except, of course, if you're writing it yourself to better learn Swift).

Sprite Kit

Sprite Kit gives developers the ability to create simple or advanced 2D games by providing animation and physics functionality.

Readings

Cheat Sheets

Tools, tricks, and tips for both novice and senior Swift developers.

Readings