Notes on Swift
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is even with mx4492:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Swift is fun. Let's say hello to it.

$ cat >hello.swift
print("Hello, swift!")
$ swift hello.swift
Hello, swift!

The primary reference is the Swift ebook. It is available as an epub file. It is recommended that you keep a text copy of that book on your machine locally, so that you can use it as a man page and quickly grep for stuff if you have doubts:

curl -LO
pandoc TheSwiftProgrammingLanguage\(Swift3\).epub -o swift3.txt -w plain

For naming conventions, go through the Swift API design guidelines.

Apple's Swift Blog is the new NSHipster.

Swift comes with five different "assertions"; see the first section ("API") of Mike Ash's introduction.

RxSwift is Swift port of Rx. It unifies KVO observing, notifications, async operations and streams under the same abstraction. See the transcript of the talk by Max Alexander for a tutorial.

Coding Conventions


Use 4 spaces.

No Boilerplate

The default Xcode Templates have auto-generated boilerplate at the top of your source file; you can remove them with the following command:

find -E $(xcode-select --print-path) -regex '.*___\.(c|h|m|swift)' -print0 | xargs -0 -n 1 sed -i '' '1,/^$/d'

You will have to run this each time you update Xcode.