
Ok… Let’s talk about Swift
I first decided to start writing blogs in order to learn more about Swift but as you could probably tell from my previous posts, I’ve yet to mention anything about Swift. So.. here it is. Let’s go full Swift on this thing.
The First Encounter
My first encounter with Swift was late August of 2015. I had just started my internship at Detroit Labs and was given an assignment; to build an app from scratch. Oh and by the way, this app wasn’t just a basic ‘oh let the stupid interns make something cute while they are here’ kind of project. This was a full-fledged, ‘here’s one of our senior developers and he will be in charge’ kind of project. The project was a family tracking application and was supposed to have features like messaging, child tracking, task management and much more. At the time, I had about two years of Objective-C experience so I was assigned as the head of the iOS team; or I would like to think so :)
So, after brainstorming about what this app is going to be, we faced our first big question; what language are we going to use? Swift had been released couple of months before during WWDC 2014 and I knew about some of its features but hadn’t been introduced to it at all. Plus, the other iOS team members had almost zero iOS development experience so it was down to me to make the call. I looked around on the web about how production coding in Swift is like and at the time reviews were pretty bad. Constant SourceKit crashes and compiler segfaults were pointed out as main problems for Xcode (v.6.1 I think?) and people were not recommending using Swift for production coding. But, I thought it should be fun so I said, “Why the hell not?” and chose to go with Swift. This is where things got interesting…
The Bugs
I started off being amazed by some of Swift’s features. The whole immutability and preferring functional programming was new to me but as time went on, I got used to it. Syntax was weird but it also was something I could get used to over time. Having a single .swift file instead of having a .h and a .m file was cool (I’ll talk about more cool stuff later on) All was fun and games until the bugs came in.

Anyone who’s had this will know how much of a pain in the ass this is. Auto-complete stops working, syntax highlighting stops working and it just seemed like the world was closing in on me as even my most trusted pal Xcode was turning its back on me.
Fast forward couple of months and I have to deal with enterprise code signing issues and the fact that CocoaPods version supporting Swift was a v.1.0 at the time. I think I lost about 30% of my hair during those 3 months but looking back to it, I think there may have been more to it than just having had to deal with the bugs and the instability.
Good Guy Swift
Swift is an amazing language. With all of its Protocol Oriented Language features, I believe it’s the best way to write “code that we can reason about.” For example, how many times have you written code like this for your UITableView?
if (indexPath.section == 0) {
if (indexPath.row == 0) {
}
else if (indexPath.row == 1) {
}
...
} else if (indexPath.section == 1){more stuff here...
}
Every time I have to write or read this kind of code, I want to cry. But fear no more, as with Swift, you can do stuff like this with the power of pattern matching.
switch(indexPath.section, indexPath.row) {case (0, 0):
case (0, 1):
case (more here):
default:
//something elegant here
}
Ok, that’s a lot better. Tuples are actual useful after all. But hold on, I think we can do better. After all, it’s Swift, right? So, how about this?
case (let row, 0):
case (let section, 0) where section % 2 == 0:
case (let row, 0) where validate(row):
This is some powerful stuff and with this kind of syntax, I think a lot of beautiful, readable yet reasonable code can be written.
The Future
There are so many things that I want to talk about Swift such as enums, generics, protocols, closures, and more but I think this is enough intro for now.
I’ve been first introduced to Swift in a very informal manner so I want consider me writing these blogs as an official way of me getting to know Swift more and more. So, here’s to learning Swift…. I hope you guys follow me in my journey and become more Swifter day by day.
Deuces