【问题标题】:Migrating an iOS application using Cocoapods 1.0.1 from Swift 2.2 to 3.0将使用 Cocoapods 1.0.1 的 iOS 应用程序从 Swift 2.2 迁移到 3.0
【发布时间】:2016-09-28 20:42:32
【问题描述】:

我目前正在将 iOS 应用从 Swift 2.2 升级到 3.0。我已将我所有的 pod 依赖项指向他们的 Swift 3 版本,并迁移了我的代码。但是,当我运行pod install 并尝试打开我的工作区时,Xcode 仍然希望我将“Pods”项目转换为最新的 Swift 语法:

“Pods”项目的目标包含使用早期版本的 Swift 开发的源代码。

但我已经将我的依赖项升级到他们的 Swift 3.0 版本。什么给了?

(这是一个规范的问答对,以帮助遇到此问题的未来用户)

【问题讨论】:

    标签: ios swift cocoapods swift3 xcode8


    【解决方案1】:

    我在使用 Cocoapods 1.0.1 时遇到了这个问题,我需要手动将已安装目标的 SWIFT_VERSION 指定为 3.0:

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

    我的完整 Podfile(用于测试/开发 pod):

    source 'https://github.com/CocoaPods/Specs.git'
    
    use_frameworks!
    
    target 'MyApp' do
      pod "MyPod", :path => "../"
    end
    
    target 'MyApp_Tests' do
      pod "MyPod", :path => "../"  
    end
    
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['SWIFT_VERSION'] = '3.0'
        end
      end
    end
    

    Issue #5521 - Compiler Version for Xcode 8 帮助找到了这个解决方法。

    【讨论】:

    • @JonShier 我是否必须订阅特定的 beta 频道才能获得候选发布版本?我没有看到普通的“pod update.
    【解决方案2】:

    我建议使用他们的候选发布版本

    sudo gem install cocoapods --pre
    

    然后再次安装 pod

    【讨论】:

    • 对,但如果您所在的团队不支持 Cocoapods 的预发布和发布候选版本(并且停留在 1.0.1),那么这不是一个可行的解决方案。
    • 改用 Swift 包管理器?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多