A Weekend Wasted (Well Spent) on Swift

A Weekend Wasted (Well Spent) on Swift

Personal apple ios-development swift wwdc2014 xcode

A Weekend Wasted (Well Spent) on Swift

So I did not do a single productive thing this weekend that wasn't typing curly braces into Xcode. Worth it though.

If you missed it, which you probably didn't because it's been all over every dev forum I read since Monday, Apple used the WWDC keynote to drop a brand new programming language on us out of nowhere. Not a rumor, not a leak, nothing. Craig Federighi just started talking about "Swift" like it was a thing everyone already knew about, and the room lost it. I watched the stream at my desk with a lukewarm coffee and actually said "wait, what" out loud to an empty apartment.

I've been doing iOS stuff on the side for about two years now, mostly small utility apps, nothing anyone's heard of, and Objective-C has just been the tax you pay to be in that world. The brackets, the header files, the NSString this and NSMutableArray that. You get used to it the way you get used to a squeaky floorboard. So when Apple hands you something that looks almost like Python had a baby with Objective-C, minus the syntax noise, it's hard not to get a little excited.

I downloaded the Xcode 6 beta Thursday night (had to dig up my paid developer account login, which I'm fairly sure I set up specifically for App Store submissions and haven't touched since) and it chewed up a solid chunk of my hard drive and probably twenty minutes of my evening just installing. Then I spent most of Saturday afternoon just poking at it.

A few things that actually surprised me:

No semicolons. You genuinely don't need them. I put them in for the first hour out of pure habit and nothing broke, Swift just quietly ignored them, but eventually I made myself stop. Old habits are stupid that way.

Playgrounds are the best part, honestly. You write code in this side panel and it shows you the result live, right next to the line, no compiling and running a simulator just to check if a loop does what you think it does. I made a dumb little playground that just drew a sine wave by looping through values and it rendered the graph right there inline. That's the kind of thing that makes you want to keep going for another hour when you should be making dinner.

Optionals took me a minute. The whole ? and ! thing for values that might be nil is one of those ideas that's clearly smart and clearly going to trip me up in code review for the next six months. I already caused myself a force-unwrap crash within like fifteen minutes of writing my first real function, which felt almost like a rite of passage.

Apple also put the whole language reference up as a free book on iBooks the same day, several hundred pages, and I actually read a chunk of it on the train Friday instead of the usual podcast, which is not a sentence I expected to type in 2014.

Now, is any of this going in a real app anytime soon? No. It's still beta, it can apparently only build for iOS 8 and Yosemite betas right now, and I am not about to submit something built on a language that's a week old to the App Store. My existing apps are staying in Objective-C for a long while yet, probably interoperating with a little Swift here and there once it's actually stable, since apparently you can mix the two in one project, which is at least smart planning on their part.

But I'll say this: I went into the weekend assuming this was going to be a fad thing I'd poke at once and forget, and instead I've got three half-finished playground files open right now and a nagging urge to rewrite one of my smaller apps just for the practice. My roommate asked if I wanted to go get food around 7 and I told him to give me twenty more minutes, which turned into an hour and a half, and he was annoyed about it in a way that was completely fair.

Not sure what my actual takeaway is here except that it's rare a big company hands developers something genuinely new to play with instead of just an incremental SDK bump, and I forgot how fun that feels until I was three hours deep in it on a Saturday I had no other plans for.

Anyway. Back to the playground. There's a bug in my sine wave thing and it's bothering me.