使用Xcode8和一个使用cocoapods的swift 2.3项目

时间:2023-01-27 10:53:20

I have a project with a light amount of code written in what I assume is swift 2.3 It contains and app extension also written in swift 2.3 and uses 2 Cocoapods: SwiftyJSON and MMWormhole. After downloading Xcode 8.3 beta, the migrator ran and I am left with almost 100 compiler errors in the one main swift file contained in SwiftyJSON.

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

Basically I want to know if there is a way I can work in Xcode8 given these details. I am happy to update my own code to swift3 however I do not control the cocoapods (MMWormHole is in objective-C so I assume that Xcode converts that to whichever version of Swift it needs as it emits no compiler errors). Can I tell Xcode to use swift 2.3 globally?

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

4 个解决方案

#1


6  

You have to set Use Legacy Swift Language Version to YES to make use SWIFT 2.3 code in Xcode 8. Then add this into your Podfile to make all of your pod targets confirm the same.

您必须将使用旧版Swift语言版本设置为YES才能在Xcode 8中使用SWIFT 2.3代码。然后将其添加到您的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

I hope, it will help.

我希望,这会有所帮助。

#2


2  

Many open source Swift projects have branches for Swift 3 or Swift 2.3 (see this post for details on a popular approach). I checked SwiftyJSON and it appears to have a branch for Swift 3, so you could convert your app to Swift 3 and give that a try. In order to use it, change the SwiftyJSON entry in your Podfile to:

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

pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git', :branch => 'swift3'

It's up to the project to update for each Xcode 8 beta, so it may not be exactly working, but it is likely that there will be fewer than 100 errors.

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

Note: You may see a “Use Legacy Swift Language Version” error after updating everything and fixing the complier errors. This can be fixed by adding a post_install step to your Podfile (see this GitHub issue), or by updating to CocoaPods 1.1.0.beta.1 or higher (gem install cocoapods --pre).

注意:更新所有内容并修复编译器错误后,您可能会看到“使用Legacy Swift语言版本”错误。这可以通过向Podfile添加post_install步骤(请参阅此GitHub问题)或更新到CocoaPods 1.1.0.beta.1或更高版本(gem install cocoapods --pre)来解决。

#3


0  

From my experience when starting up the workspace, the SDK should ask you if you'd like to convert your code to Swift 3 or do it "later". By just selecting later, it won't migrate your code to swift 3. I must warn you though that I went through the same thing and it was almost impossible to work backwards just because you want to use the latest and greatest Xcode 8. You'll eventually run into problems such as when you're ready to push to the app store and iTunesConnect won't accept any files that are lower than version 10. Also when and if another developer inherits your code, they will have problems if they are using an earlier version of Xcode.

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

#4


0  

Add the following to the end of your Podfile then run pod install:

将以下内容添加到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

#1


6  

You have to set Use Legacy Swift Language Version to YES to make use SWIFT 2.3 code in Xcode 8. Then add this into your Podfile to make all of your pod targets confirm the same.

您必须将使用旧版Swift语言版本设置为YES才能在Xcode 8中使用SWIFT 2.3代码。然后将其添加到您的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

I hope, it will help.

我希望,这会有所帮助。

#2


2  

Many open source Swift projects have branches for Swift 3 or Swift 2.3 (see this post for details on a popular approach). I checked SwiftyJSON and it appears to have a branch for Swift 3, so you could convert your app to Swift 3 and give that a try. In order to use it, change the SwiftyJSON entry in your Podfile to:

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

pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git', :branch => 'swift3'

It's up to the project to update for each Xcode 8 beta, so it may not be exactly working, but it is likely that there will be fewer than 100 errors.

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

Note: You may see a “Use Legacy Swift Language Version” error after updating everything and fixing the complier errors. This can be fixed by adding a post_install step to your Podfile (see this GitHub issue), or by updating to CocoaPods 1.1.0.beta.1 or higher (gem install cocoapods --pre).

注意:更新所有内容并修复编译器错误后,您可能会看到“使用Legacy Swift语言版本”错误。这可以通过向Podfile添加post_install步骤(请参阅此GitHub问题)或更新到CocoaPods 1.1.0.beta.1或更高版本(gem install cocoapods --pre)来解决。

#3


0  

From my experience when starting up the workspace, the SDK should ask you if you'd like to convert your code to Swift 3 or do it "later". By just selecting later, it won't migrate your code to swift 3. I must warn you though that I went through the same thing and it was almost impossible to work backwards just because you want to use the latest and greatest Xcode 8. You'll eventually run into problems such as when you're ready to push to the app store and iTunesConnect won't accept any files that are lower than version 10. Also when and if another developer inherits your code, they will have problems if they are using an earlier version of Xcode.

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

#4


0  

Add the following to the end of your Podfile then run pod install:

将以下内容添加到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