Swift 1.2 Presentation and Notes (Swift London 17th Feb)

This isn't a proper blog post but I wanted to share the slides and notes from my talk on Swift 1.2 tonight. I'll post a link when the video goes up.  The video is now available here.

One thing that I forgot to mention in the talk is late initialization of let variables. The example Swift 1.2 code does show it though.

Comments, questions and suggestions all welcome.

Slide Text and Notes

Lines starting with `^` are my notes. These were hints to me, they are not a full script.

Swift 1.2

Joseph Lord - @jl_hfl

There are just literally thousands of fixes in Swift 1.2, and we cannot enumerate them all in a useful way in the release notes. -- Chris Lattner

^ 33 bullets in the release notes for language changes.

Beta Health Warnings

Will crash, will have bugs, will annoy you

Can't submit to the store until Xcode 6.3 is released

^Even 6.1 GM could not submit to the App Store.

Source code changes required

^Can't just swap Xcode 6.1 back in for your release.

^ My recommendation is unless the performance is critical do not use it yet.

^ If you need to ship before June just branch to test builds using 6.3 to see how big the impacts will be and whether there are any valuable warnings or indications of required as! casts that you may want to resolve but don't shift development yet.

It's Great

^ This is a really big change, significant step for Swift, don't underestimate it.

Safer, More flexible

^ as!, less automatic Foundation casting. noescape on closures (implied by @autoclosure)

^ More advanced structs are possible.

Nicer syntax for common cases

Faster (builds and binaries)

^ Incremental builds. Faster optimised and debug builds. Debug still pretty slow. ^ Some code 2 or 3 times faster (10x Debug but that is still >10x slower)

Improved error messages

^ Apparently the errors are improved.

^ Here is some Swift 1.2 code

^ This is not how to code in Swift 1.2 but how many new features can I pack into a few lines.

^ static in class aliases class final ^ static stored properties in classes, which have global storage and are lazily initialized on first access (like global variables)

^ Set

^ if let multiple - Pyramid of doom fix

^ if let where

^ as changed to as! so that you can see dangerous casts

^ let - non-immediate initialisation (Don't think this actually works with globals (e.g. in a Playground)

struct Advancements



and isUniquelyReferencedNonObjC


Edit > Convert > To Swift 1.2

Migrator has issues with nil coalescing ??

Allow time to get it compiling and working properly.

as you like it

as - Safe upcast (subClass as parentClass) OR type annotation e.g. 0 as Int8

as! - Forced cast, runtime error if cast fails

as? - Failable, nil if cast fails


Indicates closure argument will not be retained beyond function call.

Safety and performance.

Automatic for @autoclosure

^ autoclosure syntax has changed - Xcode will set you right

^ Next beta will let @autoclosures opt out of @noescape ^ @autoclosure only for parameters not properties (need to use Box instead)

Foundation Bridging

NSString, NSArray, NSDictionary

Will no longer be implicitly cast to Swift types.

Use as casts to convert when required.

Swift types will still implicitly convert to Foundation types.

Objective C (boo hiss)




null_resetable (for properties)

Swift enum access

^ Actually really good news for Swift users. Boo hiss only because it was a Swift London event there is nothing wrong with Objective C, it is just different.

^ The parentheses are acknowledged as a bug and will be fixed probably in the next beta.

^ Automatic bridging from Foundation types to Swift types is disabled. (Safer more predicatable)

Links and Sources

Xcode 6.3 Beta Release Notes May be available only to registered developers.

AirspeedVelocity - Best place for Standard Library changes.

^ Airspeed includes how to create your own value types with isUniquelyReferencedNonObjC

FlexMonkey - Article on Sets

Round up of posts


Available for contracting or the right permanent role. Also available to provide Swift training advice and coaching to individuals, companies or groups.

Twitter: @jl_hfl Blog: blog.human-friendly.com

NSThamesValley Meetup for iOS and OS X Developers - Kicking off 18th Feb at Green Park near Reading. Please RSVP and join us.