Andy Ibanez
Andy Ibanez

Reputation: 12254

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

I'm trying to build a Cocoapod that (currently - this will change when iOS 9 and Xcode 7 are out of beta) depends on different branches of Alamofire and SwiftyJSON. This is because my Cocoapod was coded in Swift 2.0. To be more specific, my pod currently depends on the swift2-0 Alamofire branch and xcode7 SwiftyJSON branch.

My Podspecs file currently looks like this:

#
# 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]" }
  s.source           = { :git => "https://[email protected]/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

Like you can see, I am specifying the dependencies for Alamofire and SwiftyJSON in the last two lines before end.

I read in another StackOverflow answer that I cannot specify the branch for my dependencies in the Podspec, so I should specify them in my Podfile instead. I did that:

# 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

Then, because my project is using iOS 9/Xcode 7 technologies, I changed the command line tools for Xcode to use Xcode 7 beta (Xcode > Preferences > Locations > set "Command Line Tools" to Xcode 7) and tried linting it. It fails:

 - 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

(It throws many more errors, but all of them have to do with things that changed from Swift 1.0/1.2 to Swift 2.0).

Of course, this can only mean that Cocoapods is downloading the official branch for the Alamofire dependency, because Swift 2.0 effectively removed the # syntax that was used to create a function parameter label and variable with the same name. The swift2-0 branch fixes this.

If I run my unit tests, they all compile and run fine, so something is making Cocoapods use the master branches versions of my dependencies instead of the ones I explicitly define in my Podfile.

Is there any way I can set different branches dependencies for my pods? This will only be used temporarily, as I want to start building my iOS 9 app and test my pod in a real case. As soon as Xcode 7 is out of beta, the the branches I'm using for my pod will most likely be merged with their respective masters, and I won't have to find workarounds to make them work anymore.

Upvotes: 4

Views: 3014

Answers (1)

Andy Ibanez
Andy Ibanez

Reputation: 12254

I asked in the Cocoapods Repository and one of the contributors answered my question.

Linting (and therefore, trying to upload your pod) runs on your Podspec, not Podfile, and there is no way to specify a different branch in the Podspec.

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

What I want to do is, therefore, sadly not possible.

Upvotes: 2

Related Questions