SWIFT, DARWIN’S FAVOURITE LANGUAGE
Apple introduced its new programming language almost two years ago and since then they’ve updated the language four times with new features and improvements.
Swift has reached a critical mass. Based on TIOBE index of popularity, Swift has ascended above Objective-C. Ryan Olson, the respected iOS Engineer has downloaded the top 100 iOS apps from the AppStore, and 11% of them are using Swift, and that number is exponentially growing.
The majority of iOS applications are written in Objective-C, and the industry is migrating to Swift step by step by mixing and matching the two languages or rewriting the entire application. Swift defines itself as a modern language with an intuitive and efficient syntax, designed for safety and security in mind. While still a very young language, it’s evolving at a rapid pace.
Swift produces an overall shorter code length and since it’s a functional programming language, you can pass a function as a variable. This results in highly generic code that most importantly reduces repetition.
One of the major Objective-C holdbacks was the C. Programmers had to maintain two files “.h” with all the method signatures, protocols and “.m” file for all the implementation. However with Swift, the programmers have to maintain one single file with “.swift” extension which contains everything.
The next major issue was memory management. It was an effort to go after memory leaks and NSZombie objects to retain counts. Particularly for the earlier versions of the iPhone that had a limited amount of memory. This prompted Apple to introduce ARC (Automatic Reference Counting) to Objective-C in 2011. However, for procedural C code and APIs like Core Graphics, it was the programmer’s responsibility to handle memory management when working with the Core Graphics APIs and other low-level APIs available on iOS. The massive memory leaks that a programmer can have in Objective-C are almost impossible in Swift.
Swift is Open Source. Apple has unlocked a key piece of functionality that has previously restricted Swift to Apple’s walled-garden platform. Therefore, the contribution from the community will be accepted and encouraged. The best part is that the source code will include the Swift compiler and standard library. In the end, open sourcing Swift means it’s going to change rapidly. Typically, these rapid changes could hint of troubles for engineers. We’ve even seen this in Swift to a certain degree. Swift 2.0 introduced many changes that made Swift 1.0 code obsolete and uncompilable. To demonstrate this, consider these metrics that the Swift repository has undergone in the short time it’s been live:
- 10,000 commits occurred in the first 24 hours
- over 35,000 commits to date
- 400 pull request have been merged to Swift’s repositories
At the time of writing, Swift is also steadily trending at the #1 spot on GitHub. That’s quite an accomplishment in a short amount of time, and it clearly shows the readiness of the development community as a whole and how willing they are to contribute.
In summary, Swift is going to define Apple’s future in software development. OS X and iOS are updating rapidly, and they are adopting Swift at a very fast pace. Swift is going to define the next ten years for Apple Engineers and the App developer.