【问题标题】:Alamofire Xcode 8 Swift 3 results in 786 compile errorsAlamofire Xcode 8 Swift 3 导致 786 编译错误
【发布时间】:2017-01-15 19:06:37
【问题描述】:

我正在使用 Xcode 8.0 GM。我创建了一个默认的单视图应用,并将我的部署目标设置为 9.0。

在我的 Podfile 中,我的目标是最前沿的 Swift 3 分支:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target 'MyProject' do
    pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'swift3'
end

我运行pod install 并得到...Installing Alamofire (4.0.0-beta.2) ...太棒了,没问题。我打开MyProject.xcworkspace

这会弹出:

我不能稍后再打,因为它告诉我:

Xcode 8 将无法构建目标“Alamofire”,并且某些编辑功能在此目标中的 Swift 源代码被转换之前将无法正常工作。

这不好,我想建造它。所以我点击“转换”。它给了我选择:

这就是我想要的,Swift 3。看起来不错,我点击“下一步”。

它默认为这 3 个选定的目标。好吧好吧,我下一个。

以上帝的名义……

我想在针对 iOS 9.0 的 Xcode 8、Swift 3 项目中使用 Alamofire 的 swift3 前沿分支。我哪里出错了,我怎样才能让它工作? FWIW 我在尝试使用 Alamofire 的 Swift 2.3 分支时遇到了一堆错误,所以我知道这是我做错的事情。

【问题讨论】:

  • 向alamofire开发者询问支持Swift-3的版本,请不要使用Xcode转换工具。
  • 他们的 swift3 分支支持 Swift 3。这是我不明白的。
  • 那很奇怪,也许我们应该等他们几天:(
  • 我不认为是他们我认为这是我做错了。
  • 在最新的 XCode 8 中有一个错误,构建会随机失败,列出数百个实际上不存在的错误。当我看到这一点时,我只是再次构建,然后它们就消失了。我已向 Apple 报告。

标签: ios swift xcode cocoapods alamofire


【解决方案1】:

通过以下命令升级到最新的 Cocoapods(在此回答时:版本 1.1.0.beta.2):

gem install cocoapods --pre 似乎解决了我的情况。

【讨论】:

  • 我遇到了同样的问题。我已经将 Cocoapods 更新到 1.1.0.beta.2,尝试再次安装 Alamofire,但它仍然不适合我...
  • @Rados 您应该检查 pod --version 使用的 Cocoapods 版本。旧版本仍在使用中,因此您可以使用gem cleanup仅保留最新版本的 Cocoapods。
  • 这是 Xcode 本身的问题(我使用的是 Xcode 8 beta 6)。当我下载 Xcode GM 时,一切都按预期进行。
  • 谢谢,对我帮助很大!
  • 这并没有帮助,它变得更糟了。我在这行代码 `urlSession = URLSession(configuration: URLSessionConfiguration)` 上有 4 个错误
【解决方案2】:

我能够让它工作:

更新:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

target 'PROJECT NAME HERE' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!
  pod 'Alamofire',
    :git => 'https://github.com/Alamofire/Alamofire.git',
    :branch => 'swift3'

end

pod 更新 Alamofire

It should update to 4.0.0-beta.2

收到请求时有一些变化:

旧:

Alamofire.request(URL_NAME_HERE, withMethod: .get).responseJSON { response in
     //Code here.
}

新:

Alamofire.request(URL_NAME_HERE, method: .get).responseJSON { response in
     //Code here.
}

希望这会有所帮助。

【讨论】:

  • 他们特别提到要在 Stack Overflow 上写一个问题并用“Alamofire”标签标记它。我几乎把句子放在我原来的问题中,期待这样的答案。
  • 打开项目出现“Convert to current Swift syntax”提示时你是怎么做的?而你使用的是 Xcode 8 GM?
  • 我从未转换过。是的,Xcode 8 GM(现在一直在使用 swift 3)。如果您已转换,请恢复为您的工作副本。
  • 没有名为swift3的分支
  • 在 swift 3 正式发布后,没有 swift3 分支了。您必须改用: pod 'Alamofire', :git => 'github.com/Alamofire/Alamofire.git', :branch => '4.0.0-beta.2' 但有 404 个问题...
【解决方案3】:

您现在应该使用master 分支,因为swift3 分支已在此处合并。此外,Xcode Migrator 显示很多错误是正常的。它正在做什么编译代码,认为它是一个遗留的 Swift 版本,但由于它已经在 Swift 3.0 中,所以错误是意料之中的。最后,Xcode 要求您转换为现代 Swift 语法,可能是因为您没有使用最新版本的 Cocoapods 安装 Alamofire。

注意:虽然 Cocoapods 告诉你使用 gem install cocoapods --pre,但我更喜欢使用 gem update cocoapods --pre。否则,旧版本的 Cocoapods 会保留下来,并且在使用 pod update 时仍然可以使用。通过pod --version检查您使用的版本。

【讨论】:

    【解决方案4】:

    使用以下命令将 pod 更新到 1.1.0.rc。

    sudo gem install cocoapods

    最后使用打击 sn-p。

    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

    这有帮助。

    【讨论】:

      【解决方案5】:

      解决方案是从这里更改您的请求

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

      到这里

      pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'master'
      

      【讨论】:

        【解决方案6】:

        我通过使用解决了类似的问题

        pod 'Alamofire', '~> 4.0'
        

        在 pod 文件中。我确实不得不调整到更高的最低部署目标。

        【讨论】:

          【解决方案7】:

          我通过使用解决了类似的问题:

          platform :ios, '9.0'
          use_frameworks!
          target 'PROJECT NAME HERE' do
          pod 'Alamofire'
          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
          

          【讨论】:

            【解决方案8】:

            我遇到了同样的问题,但我卸载了 cocoapods,卸载了 alamofire,然后将我的可可豆荚更新到 1.1.0.beta.2,然后在我的 pod 文件中使用了 Alamofire 的 swift3-rebased 分支

            pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'swift3-rebased'

            打开我的 Project.xcworkspace 文件,Alamofire 的所有编译错误都消失了。

            【讨论】:

            • 好吧,现在是可可豆荚 1.1.0.rc.1 和 Alamofire 4.0。
            【解决方案9】:

            不确定这是否对任何人有帮助,但以防万一.. 我尝试使用 CocoaPods 独立应用程序将 Alamofire 添加到 Xcode 8.0 GM 上的示例快速应用程序中。我不断得到“转换为 swift 2.3 或 3.0”窗口。但后来我尝试从命令行更新 pod 并且它工作正常。不知道为什么..我认为独立应用程序的底层命令是相同的..所以不确定是什么造成了不同。无论如何,在浪费了 30 分钟的时间后,我的工作。

            这是命令行截图..同一个pod文件

            【讨论】:

            • 简单:CocoaPods 应用程序使用 CocoaPods 工具 (1.0.1) 的发布版本,它不考虑 Swift 3,而您可能已经将命令行工具更新为预发布 1.1.0
            【解决方案10】:

            您需要使用版本 4.0pod 'Alamofire', '~> 4.0' 注意需要 CocoaPods 1.1。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2017-02-08
              • 2017-01-26
              • 2017-09-21
              • 2020-06-23
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多