BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Swift Turns 1.0: The Evolution of a Language

Swift Turns 1.0: The Evolution of a Language

Bookmarks

Apple has announced that Swift 1.0 has reached GM status on iOS and developers can now start submitting apps that use Swift. The language will continue to "advance with new features, improved performance, and refined syntax", say Apple, as it has done since its announcement at WWDC 2014 last June.

Before reaching GM status for iOS, indeed, Swift has gone through a number of beta releases that, besides fixing the inevitable bugs, have progressively refined the language syntax and semantics, and improved performance.

Swift Syntax and Semantics

With each new beta release, Apple updated its official Swift Language Reference to keep it in sync with the language new features. Xcode release notes, on the other hand, have hosted all the details about what changed in Swift from one beta version to the next, although mixed-in with the full set of Xcode changes.

This is where SwiftInFlux, a GitHub repository created by Karol S. Mazur, can come in handy and provide a glimpse of all the changes made to Swift in a structured way. What makes this repo particularly interesting is that for several of the changes made to Swift, we can read Swift creator Chris Lattner's opinion on what they meant and why they were added.

Besides listing in a concise way all the changes that each Xcode beta version brought to Swift, the repo also collects some change requests that have been discussed either in Apple developers forums, or reported to Apple through Radar. A few highlights of areas where Swift might see further development beyond 1.0 are: abstract methods, access control, C++ support, nil returning initializers, and others, though there is not any commitment on Apple part, yet.

Swift Performance

When Swift was announced, Apple touted its speed as one of its most remarkable features, with a 40% performance increase over Objective-C. Still, initial tests done by several developers showed a rather different picture, with Swift being outperformed by Python in several tests unless using the -Ofast compiler optimization option, which also removed all runtime safety checks. This finding sparked online discussions where several developers hinted at the work in progress nature of Swift and remarked that it was not so uncommon for a beta release to show performance issues.

Indeed, all of Swift performance issues were fixed as early as the beginning of last month with the release of Xcode 6 beta 5. As developer Jesse Squires reported, in Xcode 6 beta 5 Swift for the first time outperformed Objective-C in all the algorithms he had been testing since Swift was first made available. Even better results could be achieved by enabling a new -Ounchecked optimization option, which replaced -Ofast and made more explicit its real behaviour, putting Swift performance on a par with C's, albeit doing away with any optimizations, as already mentioned.

Mike Ash wrote a very detailed analysis of the reasons why Swift can outperform Objective-C, taking into account faster method dispatching thanks to static dispatching, more opportunity supported by the language for inlining function calls, more efficient register usage thanks to not having to handle the _cmd implicit parameter to any method call, and pointer aliasing, which could allow to optimize cases where more pointers refer to the same memory area.

Swift for OS X

Swift has not reached GM status for OS X, yet, due to the dependency with Yosemite SDK. Apple say that when Yosemite will reach GM, Swift will also be GM on the Mac. Meanwhile, developers can build Mac apps with Swift by downloading the beta of Xcode 6.1. Xcode 6.1 will already include a few improvements to Swift by the time Yosemite reaches GM, say Apple in the Swift announcement. No compatibility issues are foreseen, though, since "apps today embed a version of the Swift GM runtime and they will continue to run well into the future" in spite of any changes to the language definition.

Rate this Article

Adoption
Style

BT