Swift Finally Matches Objective-C in One Major Way

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 NSDictionary to Dictionary is 1.6x faster; NSString to 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.

3 Responses to “Swift Finally Matches Objective-C in One Major Way”

  1. jpmorgan chase

    Why risk a slower app just to move to a new language? – is this even a valid question? In modem software engineering world, especially client side, efficiency perhaps is the least concern. Otherwise just use assembly languages.

  2. Bohalo

    Because of that attitude, many of the apps these days heavily relies on newer hardware for performance issue. We used to try to optimize for the best scrolling performance with 60fps constant as target, nowadays all people care is less code and it runs. Texture(formerly named AsyncDisplayKit) was built for this as well. Engineers these days seem to care about how to cut down the coding than knowing how to truly engineers it. Code monkey…

  3. James Bush

    What an ignorant article. Swift is an abstraction of Objective-C. They are not two branches off the same trunk.

    Swift is nothing more than a convenience. It’s not revolutionary, it’s not new. It’s a way to make everybody fit form. There’s no upgrade when you switch from Objective-C to Swift; so, the question is never going to be, “When is everybody going to get on board with the future?”

    A ridiculous and pedantic misunderstanding on your part. Why are you writing articles on this when you don’t understand what you’re writing about?