BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Apple Open-Sources the Swift Language Migrator

Apple Open-Sources the Swift Language Migrator

Leia em Português

This item in japanese

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

BT