我正在尝试构建一个依赖于 Alamofire 和 SwiftyJSON 不同分支的 Cocoapod(目前 - 当 iOS 9 和 Xcode 7 超出测试版时,这将会改变)。这是因为我的 Cocoapod 是用 Swift 2.0 编码的。更具体地说,我的 pod 目前依赖于swift2-0
阿拉莫菲尔分行和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" => "[email protected] /cdn-cgi/l/email-protection" }
s.source = { :git => "https://[email protected] /cdn-cgi/l/email-protection/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
正如您所看到的,我在之前的最后两行中指定了 Alamofire 和 SwiftyJSON 的依赖项end
.
我在另一个 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 > 首选项 > 位置 > 将“命令行工具”设置为 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 的分支很可能会与它们各自的主分支合并,并且我将不必找到解决方法来使它们不再工作。