BT

InfoQ Homepage News Apple Open-Sources the Swift Language Migrator

Apple Open-Sources the Swift Language Migrator

Bookmarks

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
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.

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

Community comments

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

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

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.