Developing for iOS - part 1
Posted on December 3rd, 2015
In the last few months, for multiple reasons, I was drawn into developing a few mobile applications for iOS. I wanted to share a bit of my learnings and the choices I've made when it comes to it. The first one has to be language: Objective-C or Swift.
Well, I tried Objective-C. I did. For about 30 minutes. By then, I had to create 8 files, 4 headers and 4 implementations and I was trying to shape up what my interfaces would look like so I had to keep all of them open as I changed my mind. That was enough for me to give up and move to Swift.
Swift itself, the language, is actually pretty nice. It's an object oriented language with strong functional programming paradigms. It maintains many of it's inline-parameter-calls features that Objective-C copied from Smalltalk but added an important distinction between variables and 'invariables' (or constants declared with 'let' instead of 'var'). It also approaches the, now traditional, segmentation-fault/null-pointer-exception/unknown-method-in-nil issues with an interesting usage of the ! or ? symbols. A variable that can be nil HAS to be declared of its type with either a ! or a ? at the end (ex: UIButton! or Product?).
Swift also 'allows for multiple inheritance' (but not really).
The dreadful part is XCode. The imposed Apple IDE has been improving over time but it is still painful to use with Swift. Errors that don't exist, compilation times that vary, bad (or no) assistance for method invokation and the list goes on. I find myself typing the majority of the code without any sort of IDE help and common refactoring operations are still not very well tuned. The strong typing and inferring capabilities of the language get squished under the lack of help from the IDE.
In the middle, many cocoa and ios libraries are still lacking Objective-C to Swift bridges that allow you to use them from Swift code. You can usually go around it by hooking some Objective-C manually crafted bridging code but it's likely that you're going to have to change that in the future. The language itself is also changing a bit (and Swift 2.0 is now available) so you have to be ready to upgrade your applications.
Overall, I like the language. The IDE is very much behind what the best IDEs out-there can offer for top level languages. Apple is likely going to keep investing in XCode to make Swift one of it's top level languages for the IDE but it's not there yet. The libraries, bridges and upgrades will likely stabilize in the near future so I wouldn't worry too much about that. Plus, specifically for iOS devices, Apple has done a good job at pushing people to upgrade their applications as frequently as possible (even if releasing new versions is a pain from the provider's perspective).