A Swift update

A Swift update

A Swift update

Once again, I failed to live up to my good intentions to update this blog more in 2015. So as a new year starts, I thought I would do a few “catch up” posts covering events from last year.

The first one of these is a catch up on the coding front. I’d been playing with Swift right from the beginning, but early attempts at rewriting some parts of my Mac Finances application in Swift rapidly convinced me that Swift just wasn’t ready and I reverted to Objective C. However, I continued to play with Swift on the side as I do really like the language.

The advent of Swift 2.0 prompted me to ‘take the plunge’. I decided to completely rewrite the application in Swift – not because this is a good idea, but because I felt this would be the best way to really learn the language. I took me about 5 weeks to rewrite 12,700 lines of Objective C, working in my not very large amount of spare time, which is either a long time or surprisingly quick, depending on your perspective. It probably took me another couple of weeks to squash the final bugs that I had inadvertently introduced during the process. Overall, I’d say the experience was quite positive.

One of the things that I was intrigued to discover was whether Swift would produce more compact code, so I keep track of things as I converted things over. The outcome was a 13.6% reduction with a resulting Swift code base of 11,000 lines. I did make a few functional changes and refactored some of my earliest code along the way, so I can’t guarantee that this was all due to the language, but I kept track of the reduction as I went and it did seem pretty consistent. The reduction was only a little larger than number of lines of code in the objective C header files, so I think that elimination of these is probably the main saving. But what struck me the most was that the final Swift code was much cleaner and more elegant than the Objective C version and the “proof of the pudding” is that I would be really unhappy to have to switch back now.