Yesterday, Apple released its much-anticipated iOS 11 mobile operating system for iPhones, iPads, and iPods. It was accompanied by watchOS 4 and tvOS 11 updates. We also witnessed the launch of open source programming language
Swift 4.0.
Swift 4.0 is a major new release for everyone's favorite app development language, and introduces a variety of features that let us write simpler, safer code. You'll be pleased to know it's nothing as dramatic as the epic changes introduced with Swift 3.0, and indeed most changes are fully backwards-compatible with your existing Swift code. So, while you might need to make a handful of changes it shouldn't take long.
Swift 4 is included in Xcode 9. You can download the latest version of Xcode 9 from Apple’s
developer portal (you must have an active developer account). Each Xcode beta will bundle the latest Swift 4 snapshot at the time of release.
As you’re reading, you’ll notice links in the format of
[SE-xxxx]. These links will take you to the relevant Swift Evolution proposal. If you’d like to learn more about any topic, make sure to check them out.
Migrating to Swift 4
The migration from Swift 3 to 4 will be much less cumbersome than from 2.2 to 3. In general, most changes are additive and shouldn’t need a ton of personal touch. Because of this, the Swift migration tool will handle the majority of changes for you.
Xcode 9 simultaneously supports both Swift 4 as well as an intermediate version of Swift 3 in Swift 3.2. Each target in your project can be either Swift 3.2 or Swift 4 which lets you migrate piece by piece if you need to. Converting to Swift 3.2 isn’t entirely free, however – you may need to update parts of your code to be compatible with new SDKs, and because Swift is not yet ABI stable you will need to recompile your dependencies with Xcode 9.
When you’re ready to migrate to Swift 4, Xcode once again provides a migration tool to help you out. In Xcode, you can navigate to Edit/Convert/To Current Swift Syntax… to launch the conversion tool.
Official binaries for Ubuntu 16.10, Ubuntu 16.04 and Ubuntu 14.04 are available for download. Find Swift’s code here on GitHub.