在构建我的 Cocoapod 时,有没有办法指定对另一个分支的依赖?

Is there a way to specify a dependency on another branch when building my Cocoapod?

我正在尝试构建一个 Cocoapod(目前 - 这将在 iOS 9 和 Xcode 7 超出测试版时改变)取决于 Alamofire 和 [=48= 的不同分支]yJSON。这是因为我的 Cocoapod 是在 Swift 2.0 中编码的。更具体地说,我的 pod 目前依赖于 swift2-0 Alamofire 分支和 xcode7 SwiftyJSON 分支。

我的 Podspecs 文件目前看起来像这样:

#
# Be sure to run `pod lib lint ALSMAL.podspec' to ensure this is a
# valid spec and remove all comments before submitting the spec.
#
# Any lines starting with a # are optional, but encouraged
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
  s.name             = "ALSMAL"
  s.version          = "2.0.0"
  s.summary          = "A Swift wrapper for the Atarashii MAL API."
  s.description      = <<-DESC
A Swift, protocol-oriented iOS framework to interact with Atarashii MAL API, an unofficial API for MyAnimeList.net.
                       DESC
  #s.homepage         = "https://github.com/AndyIbanez/ALSMAL"
  s.homepage         = "https://andyibanez.com"
  s.license          = {:type => "MIT", :file => "LICENSE"}
  s.author           = { "Andy Ibanez" => "andy@andyibanez.com" }
  s.source           = { :git => "https://AndyIbanez@bitbucket.org/AndyIbanez/alsmal.git", :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/AndyIbanezK'

  s.platform     = :ios, '9.0'
  s.requires_arc = true

  s.source_files = 'ALSMAL/*'
  s.resource_bundles = {
    'ALSMAL' => ['Pod/Assets/*.png']
  }

  s.dependency 'Alamofire'
  s.dependency 'SwiftyJSON'
end

如您所见,我在 end.

之前的最后两行中指定了 Alamofire 和 SwiftyJSON 的依赖项

我在另一个 Whosebug 答案中读到我无法在 Podspec 中为我的依赖项指定分支,所以我应该在我的 Podfile 中指定它们。我这样做了:

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

link_with 'ALSMAL', 'ALSMALTests'

target 'ALSMAL' do
   pod 'Alamofire', :git => "https://github.com/Alamofire/Alamofire.git", :branch => "swift-2.0"
   pod 'SwiftyJSON', :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :branch => "xcode7"
end

target 'ALSMALTests' do
    pod 'Alamofire', :git => "https://github.com/Alamofire/Alamofire.git", :branch => "swift-2.0"
    pod 'SwiftyJSON', :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :branch => "xcode7"
end

然后,因为我的项目正在使用 iOS 9/Xcode 7 技术,所以我将 Xcode 的命令行工具更改为使用 Xcode 7 beta (Xcode > 首选项 > 位置 > 将 "Command Line Tools" 设置为 Xcode 7) 并尝试对其进行 linting。失败:

 - ERROR |  Alamofire/Source/Request.swift:76:30: error: '#' has been removed from Swift; double up 'user user' to make the argument label the same as the parameter name

(它抛出更多错误,但所有错误都与从 Swift 1.0/1.2 到 Swift 2.0 的更改有关)。

当然,这只能说明 Cocoapods 正在下载 Alamofire 依赖的官方分支,因为 Swift 2.0 有效地删除了用于创建的 # 语法具有相同名称的函数参数标签和变量。 swift2-0 分支解决了这个问题。

如果我 运行 我的单元测试,它们都编译并且 运行 很好,所以某些东西让 Cocoapods 使用我的依赖项的主分支版本而不是我的依赖项在我的 Podfile 中明确定义。

有什么方法可以为我的 pods 设置不同的分支依赖关系?这只会暂时使用,因为我想开始构建我的 iOS 9 应用程序并在真实案例中测试我的 pod。一旦 Xcode 7 结束测试版,我用于我的 pod 的分支很可能会与它们各自的主节点合并,我将不再需要找到解决方法来让它们工作。

我在 Cocoapods Repository 中提问,其中一位贡献者回答了我的问题。

检测(因此,尝试上传您的 pod)在您的 Podspec 上运行,而不是 Podfile,并且无法在 Podspec 中指定不同的分支。

No, non-released dependencies can only be set in the Podfile.

因此,遗憾的是,我想做的是不可能的。