WWDC 2019 has brought us a lot of Swift. It’s perhaps the first time Apple has stopped trying to convince us all to give the language a try, and started showing us what it can do. Now, the language has begun to eclipse Objective-C in a key way.
Apple was never shy about prioritizing Swift. As one developer on Twitter pointed out, once Swift dropped, Objective-C documentation and tutorials quickly started vanishing. Since then, the company has iterated on Swift and continued to shy away from Objective-C (except when necessary, such as supporting libraries and frameworks).
Swift 5 made an important step forward with ABI stability, which means Swift code worked directly with a binary interface. Before ABI stability, the only safeguard was code was compiled on the same compiler, a fingers-crossed approach Apple really had no option for avoiding.
Module stability also improved. Any library or API is a module, and modules are core to SwiftUI. Every time you need to call a function, for instance, SwiftUI refers to this as a module. Modules make the UI code powerful and extensible; module and ABI stability contribute to a strong binary framework.
Swift’s performance has also improved. For some time, when compared to Objective-C, Swift compiled slower. Because of ABI stability, performance has improved, and compile-time differences have vanished. The same app written in Objective-C or Swift 5 will compile at the same time, whereas Swift versions 4.2 and prior would be seconds behind legacy Objective-C code. Apps written in version 5 are also roughly 10-15 percent smaller than Objective-C apps.
Bridging performance also improved. Bridging
Dictionary is 1.6x faster;
String is 15 times faster. The
String performance uptick is thanks to a move to UTF-8 coding.
A lot has gone into Swift 5 to make it more stable, and those improvements have resulted in performance parity with Objective-C. This has long been a point of contention for Objective-C holdouts: Why risk a slower app just to move to a new language?
At WWDC 2019, that question was answered. It’s time to seriously consider the move to Swift.