Fork me on GitHub

1. Language Concepts

This Swift cheatsheet provides loads of code examples for language syntax and constructs.

Optionals

Structs & Classes

  • Swift Structs or Classes is an FAQ to answer the common question of whether you should use a struct or a class in various situations throughout your Swift applications.

Control Flow

  • Swift 2.0: Control Flow and Error Handling examines the modification of Swift's do-while loop to repeat-while so the do statement could be introduced in 2.0. The post also covers the guard statement with a good IPv4 address parsing example, the defer keyword and wraps up with 2.0's new error handling mechanisms. A good note in the post is the explanation of the try! (force try) keyword which calls a function that can potentially throw an error and will terminate the program with a runtime exception if an exception is thrown.

  • Apple's official Swift error handling page goes over the basics of representing, throwing and handlinge errors in programs.

Function Currying

Function currying is a concept Swift brings in from functional programming. Curried functions rewrite an existing function with multiple arguments into a new function with a single parameter as input and a function as returned output.

2. Human Interface Guidelines

The Human Interface Guidelines are Apple's vision and specific recommendations for creating effective user interfaces. There are different guidelines for iOS and OS X applications.

3. Error Handling

guard Statement

The guard statement is Swift 2 syntax for positively checking an error condition and escaping from the immediate control flow, such as the current function.

  • The answer to this Stack Overflow question on the guard statement concisely describes how guards can unwrap optionals and exit from a block when conditions are not met, instead of having to use nested if-else statements.

4. Swift 2.0

  • Swift 2.2: New Features goes into detail on the new features and some backwards-incompatible changes to the language since Swift 2.1.

  • About Swift is the official guide and language tour by Apple.

  • What's New in Swift 2? gives a high level overview for the new error handling, protocol extensions, and binding along with several other smaller additions that came with the new bump in the Swift version number.

  • Swift 2 - What's New? goes over some of the major changes in the Swift language and provides code for enums and the error handling syntax.

5. Tutorials

XCode 6 / Swift 1.x

6. Delegates

  • The Quick Guide to Swift Delegates explains the differences between using delegates in Objective-C compared with Swift, then shows how to create, add and call delegates from Swift code.

7. StackViews

UIStackView is a way to lay out app user interface elements in iOS 9+ and Mac.

8. Web Frameworks

Web Frameworks

A nascent community of server-side code libraries has sprung up since Swift was open sourced by Apple at the end of 2015. Most of these frameworks are not yet intended for production usage but over time some of them will emerge as favorites to build web applications.

  • Vapor is a framework inspired by Laravel, which is a PHP framework. There is an example project that demonstrates how a simple web application should be built with Vapor.

  • Swifton is an in-progress Ruby on Rails-inspired framework with routing, controllers, models and views similar to the model-view-controller pattern Rails web applications use.

  • Kitura is a web framework open sourced by IBM. This framework is intended to be easy to use with IBM's Bluemix cloud platform, if that's your kind of thing.

Swift web framework resources

This server-side Swift post goes into using Vapor and shows how to deploy a "Hello World" application on Heroku.

9. Best Swift Resources

Best Swift Resources

  • NSHipster has a wide range of in-depth articles on Swift, Objective-C and Cocoa APIs. It is an awesome resource that's frequently updated with new articles by many of the best known developers in the Swift ecosystem.

  • Awesome Swift is yet another "awesome" list but it contains stacks of fantastic links to code libraries and tutorials broken down into categories such as security, user interfaces and dependency management.