Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 10.2 convert multiple targets to Swift 5: Tries to compile some classes that are not part of target

I have an iOS Swift project with multiple targets.

Converting the first target to Swift 5 was easy.

Converting the second target to Swift 5, Xcode 10.2 tries to compile files that clearly exist only in the first target and fails (Because it doesn't compile all files of the first target and complains about unresolved identifiers).

What can I do that Xcode compiles only those files, that are part of the target while converting to Swift 5?

How can I convert my project to Swift 5?

Cleaning the Build folder and restarting Xcode 10.2 doesn't help.

like image 768
Gerd Castan Avatar asked Nov 06 '22 19:11

Gerd Castan


1 Answers

I just went through this process and was able to figure out a fairly simple solution from a hint in the last sentence of the Migration Guide https://swift.org/migration-guide-swift5/

When I tried to convert each target individually in my project, the second target would fail because of shared code with the first target that had already been converted. The solution is to create a new scheme that includes all of the targets that need to be migrated in a single pass.

  1. Click on the scheme button to get the drop down and select "New Scheme..."

  2. Create the scheme and then select it in the drop down and choose "Edit Scheme..."

  3. Under the "Build" section use the "+" button to add all of the targets you need to convert to the scheme.

  4. Build the new scheme with the current Swift version to confirm that all targets build correctly.

  5. Use Edit -> Convert -> "To Current Swift Syntax..." to start the conversion

This worked for me in a project with 15 targets with lots of shared Swift code that was in version 4.0.

like image 62
RobA Avatar answered Nov 15 '22 06:11

RobA