Swift Playgrounds and That Van Persie Header

Swift Playgrounds and That Van Persie Header

Personal apple personal swift worldcup2014 xcode

So Saturday turned into one of those days where I told myself I was just going to "poke around" with something for twenty minutes and then looked up and it was almost 5pm. The something was Swift. Apple dropped it on us at WWDC a week and a half ago along with the Xcode 6 beta, and I'd downloaded it that same day out of curiosity but hadn't actually opened it until this weekend, because who has time during the week.

First impression: the Playgrounds thing is genuinely fun to mess with, in a way I didn't expect from an Apple dev tool. You type code in the left pane and it just runs, live, showing you the actual values in a little sidebar as you go, no build-and-run cycle, no waiting for the simulator to boot. I was fiddling with a dumb little loop that generates a Fibonacci sequence just to watch the numbers populate in real time and it felt more like using a graphing calculator than writing a compiled language. Ive been doing Objective-C for going on four years now and this is a pretty different headspace.

That said, I am not sold on optionals yet. The ? and ! stuff, where you have to explicitly unwrap a value that might be nil or the compiler yells at you, makes sense in theory (catching nil-pointer nonsense at compile time instead of at 2am in a crash log, great, sign me up) but in practice I spent a solid twenty minutes just staring at an error about force-unwrapping an optional that I was positive had a value, because I'd declared it with var instead of let three lines earlier and the type inference did something I wasnt expecting. Small thing. Annoying in the moment. I dont think this is a dealbreaker, Im just cranky because I wanted to be done in twenty minutes and it took two hours.

Also, and this is a tiny complaint that doesnt really matter, but the beta build makes my 2012 MacBook Pro fan spin up like its trying to achieve liftoff the second the simulator opens. Not Apples fault exactly, its beta software, but I kept getting distracted by the noise.

The other thing eating my Saturday, in the background, literally on the TV across the room the whole time I was coding: the World Cup. I watched maybe forty minutes total of actual soccer this weekend and I am not even a little bit a soccer person, but last nights Spain-Netherlands match was one of those things where you hear about it secondhand and have to go watch the replay. Spain, the defending champions, got run over 5-1. Van Persies goal, the diving header off a long ball from midfield, is the kind of thing that gets replayed for years. I watched it probably six times on my phone between typing Swift syntax I didnt understand yet. Not much of a connection between the two things except that they both happened to me on the same Saturday and Im writing about my Saturday.

Back to the language stuff for a second because I know thats mostly why people read this blog. The syntax overall feels closer to something like Python or Ruby than to Objective-C, less bracket-heavy, no more @ symbols scattered everywhere, semicolons are optional (I still typed them out of habit for the first hour, its going to take a while to unlearn that). Whether any of us end up actually shipping apps written in this thing anytime soon is a different question. Its a beta of a beta of a language, the interop with existing Objective-C codebases is there but I havent tested it on anything real, and Im not about to rewrite anything I actually ship in a language that could still change syntax between now and this fall. But as a weekend toy it scratched an itch I didnt know I had.

Im going to keep poking at it tomorrow, probably build something slightly less trivial than a Fibonacci loop, maybe a basic todo list just to see how the UIKit interop actually feels day to day. If anyone else has been messing with the beta Id genuinely like to hear where you got stuck, because I have a feeling the optionals thing is going to be a recurring theme in whatever I write about this over the next few weeks.

For now, though, I think Ive earned a second viewing of that van Persie header.