使用Xcode8和一个使用cocoapods

时间:2016-07-27 16:32:39

标签: swift xcode cocoapods swift3

我有一个项目,其中包含大量代码,我认为是swift 2.3它包含和app扩展也用swift 2.3编写并使用2个Cocoapods:SwiftyJSONMMWormhole。下载Xcode 8.3 beta后,迁移器运行,我在SwiftyJSON中包含的一个主swift文件中遗留了近100个编译器错误。

基本上我想知道是否有一种方法可以在Xcode8中使用这些细节。我很乐意将我自己的代码更新为swift3但是我不控制cocoapods(MMWormHole在Objective-C中,所以我假设Xcode将它转换为它需要的Swift版本,因为它不会发出编译器错误)。我可以告诉Xcode全局使用swift 2.3吗?

4 个答案:

答案 0 :(得分:6)

您必须将Use Legacy Swift Language Version设置为YES才能在SWIFT 2.3中使用Xcode 8代码。然后将其添加到Podfile中,以使所有pod目标确认相同。

post_install do |installer| 
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |configuration|
      configuration.build_settings['SWIFT_VERSION'] = "2.3" 
    end 
  end 
end

我希望,这会有所帮助。

答案 1 :(得分:2)

许多开源Swift项目都有Swift 3或Swift 2.3的分支(有关流行方法的详细信息,请参阅this post)。我检查了SwiftyJSON,它似乎有一个Swift 3的分支,所以你可以将你的应用程序转换为Swift 3并尝试一下。要使用它,请将Podfile中的SwiftyJSON条目更改为:

mkdir: railsbridge: File exists

这取决于每个Xcode 8测试版的更新项目,因此它可能无法正常工作,但可能会有少于100个错误。

注意:更新所有内容并修复编译器错误后,您可能会看到“使用Legacy Swift语言版本”错误。这可以通过向您的Podfile添加// Hint to the CPU that we don't want to use the cache // Be sure to update this if you use manual loop unrolling _mm_prefetch(reinterpret_cast<char*>(ar_in+4), _MM_HINT_NTA); // Hint to the CPU that we don't need to write back through the cache _mm_stream_ps(ar_out_now,xmm0); 步骤(请参阅this GitHub issue)或更新到CocoaPods 1.1.0.beta.1或更高版本(gcc -std=c++14 -O3 -march=native -mavx -mfpmath=sse -ffast-math )来解决。

答案 2 :(得分:0)

根据我在启动工作区时的经验,SDK会询问您是否要将代码转换为Swift 3或“稍后”执行此操作。通过稍后选择,它不会将你的代码迁移到swift 3.我必须警告你,虽然我经历了同样的事情,因为你想要使用最新最好的Xcode 8,几乎不可能向后工作。最终会遇到问题,例如当你准备推送到应用程序商店时,iTunesConnect将不接受任何低于版本10的文件。此外,当另一个开发人员继承你的代码时,如果他们有代码,他们将遇到问题正在使用早期版本的Xcode。

答案 3 :(得分:0)

将以下内容添加到Podfile的末尾,然后运行pod install

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '2.3'
    end
  end
end