Chris Vig Chris Vig - 1 year ago 160
Swift Question

Convert single file to Swift 3 in Xcode 8?

Is there any way in

Xcode 8
to do a
Swift 2.X -> Swift 3
migration for a single file in a project that's already been converted to Swift 3?

For technical debt/legacy build process reasons, we are currently having to maintain both
Xcode 7
Xcode 8
versions of our project. This is causing headaches when we have to merge new development from
Xcode 7
over to
Xcode 8
. Since the project has already been fully converted to
Swift 3
in our
Xcode 8
branch (including a ton of hand fixes), we can't use the full-project automated converter. Therefore we are currently having to do a hand conversion from
Swift 2.2
Swift 3
for any new
files which were added in
Xcode 7
, which takes a significant amount of time.

I apologize if this has already been asked, I couldn't find any clear answer with Google.

Answer Source

I have a project with multiple targets where each target is a slightly more advanced version of using OpenGL with Swift. It's one project with multiple tutorials, if you will. When swift 3 became available, I used the converter, and noticed it works on a per target basis. With that in mind I suggest:

  1. Create a dumb target in the project.
  2. Add any files you want updated to this target.
  3. Run the conversation editor
  4. Associate or place those files back into your already converted target.

I realize it's a bit of a hack, but if it works, why not? Hope that helps.

As a side note, if you have any code dealing with Unsafe[Mutable]Pointer and you utilize alloc() or malloc(), the converter does not replace the alloc()/malloc() with the new UnsafeMutablePointer methods--allocate() and initialize(). You are likely using these if you are working with any of the C API's.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download