xcode 如何将我的 Swift 代码转换回 2.3
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37828700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Convert my Swift Code back to 2.3
提问by Adrian Humphrey
I downloaded the XCode Beta 8 and converted all of my swift code from Swift 2.3 to Swift 3. It has caused way too many problems for me and caused me to start a project I've been working on for around 4 month. How do I convert my code from Swift 3 back to Swift 2.3?
我下载了 XCode Beta 8 并将我所有的 Swift 代码从 Swift 2.3 转换为 Swift 3。它给我带来了太多问题,并导致我开始了一个我已经工作了大约 4 个月的项目。如何将我的代码从 Swift 3 转换回 Swift 2.3?
回答by Anton Tropashko
On the build settings for the target switch "use legacy swift version" from no to yes.
在目标开关的构建设置上,“使用旧版 swift 版本”从 no 到 yes。
That would switch the compiler back to the sane 2.x but won't change the code itself. The scope is limited to the new targets created for projects on older version of swift.
这会将编译器切换回正常的 2.x,但不会更改代码本身。范围仅限于为旧版本 swift 上的项目创建的新目标。
We have a potential issue though, with that what is a "legacy version" in the future version of Xcode might change.
不过,我们有一个潜在的问题,未来版本的 Xcode 中的“遗留版本”可能会改变。
回答by Luca Angeletti
First of all save a backup of your current project. Now!
首先保存当前项目的备份。现在!
Next, you mean Swift 2.2 right?
接下来,您的意思是 Swift 2.2 对吗?
If you don't have a backup and you're not using a version control system I believe the only way is opening your project with Xcode 7.3.1 and manually fixing the errors so to make the code compatible with Swift 2.2 again.
如果您没有备份并且没有使用版本控制系统,我相信唯一的方法是使用 Xcode 7.3.1 打开您的项目并手动修复错误,以使代码再次与 Swift 2.2 兼容。
If you are lucky
如果你幸运
Even if you think you are not using a version control there's a chance Xcode automatically created a local GIT repository for you. To check this open a source file of your project and then select View> Version Editor> Show Version Editor.
即使您认为您没有使用版本控制,Xcode 也有可能自动为您创建本地 GIT 存储库。要进行检查,请打开项目的源文件,然后选择View> Version Editor> Show Version Editor。
Now the main area is split in 2 columns. At the bottom of the central column that separates the 2 source codes there's a button having an icon similar to Time Machine). Press on it.
现在主要区域分为 2 列。在分隔 2 个源代码的中央列的底部有一个按钮,其图标类似于 Time Machine)。按它。
Now if below the right column you can select a different date then you are actually using GIT. Just pick a date previous to the conversion and repeat for every source file in your project.
现在,如果在右列下方您可以选择不同的日期,那么您实际上是在使用 GIT。只需选择转换前的日期,然后对项目中的每个源文件重复此操作。
回答by Jacobo Koenig
I feel you. Also learned this lesson the hard way!!
我能感觉得出你。也惨痛地吸取了教训!!
What (kinda) worked for me was opening the project in XCode 7.3.1 which reduced the errors from 230+ to 60. I was able to revert to Swift 2.2 manually doing changes such as changing Data back to NSData. If you know what changes Swift 3 made (Google it) then you might be able to fix most of your project.
对我有用的是在 XCode 7.3.1 中打开项目,这将错误从 230+ 减少到 60。我能够手动恢复到 Swift 2.2 进行更改,例如将数据更改回 NSData。如果您知道 Swift 3 进行了哪些更改(Google 一下),那么您可能能够修复大部分项目。
Good luck!
祝你好运!