BT

Your opinion matters! Please fill in the InfoQ Survey!

Apple Open-Sources the Swift Language Migrator

| by Sergio De Simone Follow 5 Followers on Jul 11, 2017. Estimated reading time: 1 minute |

Apple has open-sourced the Swift 4 migrator that is included in Xcode 9, recently announced at WWDC 2017.

The Swift migrator was completely rewritten to be part of the compiler, and not a separate tool, and to support equally well Swift 3 and Swift 4. The migrator does its job through a series of passes:

  • Pre-fix-it pass, which is executed when the compiler is not able to type-check the primary input file. When this happens, the migrator applies all fix-it suggestions from the compiler and retries the process up to two times with the aim to produce an AST representation of the code.

  • AST passes, which are carried through after the pre-fix-it pass if you are migrating from before Swift 4. This includes taking into account any changes at the API level from the previous SDK, so the source code is adapted to the new SDK API.

  • Post-fix-it pass, which tries to apply all fix-it suggestions provided by the compiler in Swift 4 mode. This step is executed up to seven times since at each fix-it step new issues may become visible.

For both the pre-fix-it and post-fix-it phases, the migrator will apply by default all fix-its associated to errors, while fix-its associated to warnings are opt-in.

It is worth noting that while migrating to Swift 4 is encouraged, it is not strictly required, since Swift 3.2 and 4 targets can coexist and be linked together. Additionally, you should not expect that migrating a code base will automatically produce a compilable project, let alone correct or idiomatic code. A number of known issues with migrating to Swift 4, including any applicable workarounds, are documented in Xcode 9’s release notes, available to all registered developers.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT