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

时间:2015-07-24 20:06:44

标签: ios swift cocoapods dependency-management

我正在尝试构建一个Cocoapod(目前 - 当iOS 9和Xcode 7处于测试阶段时会发生变化)取决于Alamofire和SwiftyJSON的不同分支。这是因为我的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的依赖项。

我在另一个StackOverflow回答中读到我无法在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&gt;首选项&gt;位置&gt;设置&#34;命令行工具&#34 ;到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中明确定义的版本。

有什么办法可以为我的pod设置不同的分支依赖项?这只会暂时使用,因为我想开始构建我的iOS 9应用程序并在真实案例中测试我的pod。一旦Xcode 7出现测试版,我用于我的pod的分支很可能会与各自的主人合并,我不会找到解决方法让它们再次工作。< / p>

1 个答案:

答案 0 :(得分:2)

我在Cocoapods Repository询问,其中一位撰稿人回答了我的问题。

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

  

不可以,只能在Podfile中设置未发布的依赖项。

因此,遗憾的是,我不想做的事情。