在 Xcode 8 中将单个文件转换为 Swift 3? [英] Convert single file to Swift 3 in Xcode 8?

查看:34
本文介绍了在 Xcode 8 中将单个文件转换为 Swift 3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 88.1 中是否有任何方法可以执行 Swift 2.X ->Swift 3 迁移已转换为 Swift 3 的项目中的单个文件?

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

出于技术债务/遗留构建过程的原因,我们目前必须同时维护我们项目的 Xcode 7Xcode 8 版本.当我们必须将新的开发从 Xcode 7 合并到 Xcode 8 时,这会引起头痛.由于项目已经在我们的 Xcode 8 分支中完全转换为 Swift 3(包括大量手工修复),我们不能使用完整项目的自动转换器.因此,对于在 Xcode 中添加的任何新 Swift 文件,我们目前必须手动将 Swift 2.2 转换为 Swift 37,这需要大量时间.

For technical debt/legacy build process reasons, we are currently having to maintain both Xcode 7 and 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 to Swift 3 for any new Swift files which were added in Xcode 7, which takes a significant amount of time.

如果有人问过这个问题,我深表歉意,我无法通过 Google 找到任何明确的答案.

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

推荐答案

我有一个包含多个目标的项目,其中每个目标都是将 OpenGL 与 Swift 结合使用的稍微高级的版本.如果您愿意,这是一个包含多个教程的项目.当 swift 3 可用时,我使用了转换器,并注意到它可以针对每个目标.考虑到这一点,我建议:

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. 在项目中创建一个哑目标.
  2. 将您要更新的任何文件添加到此目标.
  3. 运行对话编辑器
  4. 将这些文件关联或放回已转换的目标中.

我意识到这有点像黑客,但如果它有效,为什么不呢?希望有帮助.

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

附带说明,如果您有任何处理 Unsafe[Mutable]Pointer 的代码,并且您使用了 alloc()malloc(),code> 转换器不会用新的 UnsafeMutablePointer 方法替换 alloc()/malloc()--allocate()initialize().如果您正在使用任何 C API,您可能会使用这些.

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.

这篇关于在 Xcode 8 中将单个文件转换为 Swift 3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆