Coding with Swift

When Apple shocked everyone and announced Swift at its Worldwide Developers Conference this past June, I shared in the excitement that surrounded the language. I watched Apple’s sessions on Swift and it seemed as if the language was something I could understand and probably even code with. After I made my way through the session videos, I posted on Facebook that I could see in my head how Swift worked and that I was excited to try and build things with it.

As per usual, I put this off for months. Until tonight, in fact. I don’t know why. I just didn’t know how to start. But today I had an idea for a project — I’ve been using this little web tool from Raven Software to build URLs for tracking goal conversions in Google Analytics for BSU’s online news stories. I have a spreadsheet where I’ve been building 10 different URLs for each story I post; it’s not a complicated process but it’s pretty detail-oriented (since you can’t have typos) and with the workflow I’ve set up it takes me about five minutes each time. But consider that I’ve built enough of these packages for enough stories already this year that I’ve spent a total of about two hours just building these URLs — this is basic string concatenation, and it’s something that could be easily done programmatically with the push of a button. Today it finally occurred to me that this was my entry point for learning Swift.

So I did it. And I now have 87 lines of code in a Swift playground that will take a hard-coded URL with a hard-coded value for the URL’s Campaign Content argument and run a series of loops to build 10 URLs. I’m pumped; the code is sloppy (I’m using four different loops with different sets of variables where I should be using one loop with three arguments passed into it that runs four times, for instance) and I still need to take the next step of learning how to take that working Playground code and put it into an Xcode project so it’ll actually run. I also want to build a UI for it so a user can enter the starting URL and the Campaign Content variable and pass them into the program, rather than having those hard-coded. But the code works.

There are lots of ways I probably could have gone about this — I could have done something with Google’s scripts to create these URLs and then dump them directly into a Docs sheet, for example — but this way I’m building actual MacOS software, which is something I’ve wanted to do since OS X came out in 2001.

I never could seem to adequately wrap my head around Objective-C, but so far Swift works for me. I want to finish this and figure out what to build next. This is so cool.

Andy Bartlett

By day, I am the executive director of communications and marketing at Bemidji State University. The rest of the time, I'm a husband, father of three, and proponent of super heroes, lasers, space ships and explosions.

You may also like...

%d bloggers like this: