Swift Impressions

published 05 Jun 2014

Of all the announcements at WWDC the one that got me the most excited was that of Swift, the new programming language. I looked at Go and Rust earlier this year, and while I find them interesting I didn’t find a compelling reason to switch from Python, my trusty go-to language for the past few years. And even though I prefer Python for most projects, when you’re developing Cocoa applications you always feel like a second-class citizen. The crazy long method names are a small but ever-present annoyance, and I’ve spent way more time than I like trying to herd runaway exceptions in background threads.

So I’ve been on the fence lately, thinking that maybe I should trade some of Python’s ease of development for Objective-C’s promise of a more stable code base down the road. Thus, the Swift announcement couldn’t have come at a better time. The stability and performance of a modern, type safe language, together with the automatic memory management and flexible container types that Python has spoiled me with. What’s not to love?

I took the plunge and installed the Xcode 6 beta, and promptly lost a day futzing around with Storyboards and Auto Layout - I really need to take the time to learn that stuff. But then I spent most of yesterday making a silly little app to display the status of the Absolute Manage agent and what packages it has queued for install, giving Swift a proper workout. My impressions:

The Good

The Bad

The Ugly

AMSController.swift:52:38: error: cannot convert the expression's type 'AnyObject[]!' to type 'AnyObject[]!'
if let urls = fm.contentsOfDirectoryAtURL(dirURL, includingPropertiesForKeys: [], options: 0, error: &error) {
              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(I think options: 0 should be options: nil since in Swift it’s a struct and not a bitmask - at least that makes the compiler happy.)

Verdict

Overall the first impression is overwhelmingly positive, and whatever my next Cocoa project will be I’m certain that I’ll be writing it in Swift. The only problem is that the toolchain is currently too buggy for actual work, but I’m sure that will improve in the next couple of betas.