Adding a Forked Pod as a Dependency in a Podspec on iOS

Cristian
Written by Cristian on
Adding a Forked Pod as a Dependency in a Podspec on iOS

You’re developing a new CocoaPods library. You found a bug in one of your library dependencies, so you decide to fork that pod dependency and fix it.

After pushing the fix to the forked repository, you want to update your s.dependency with the new version of your forked pod dependency.

Here, you get an error while running pod install and you learn that CocoaPods doesn’t support :git => [...] in a .podspec file.

[!] Invalid 'my-new-lib.podspec' file: [!] Podspecs cannot specify the source of dependencies. The ':git' option is not supported. ':git' can be used in the Podfile instead to override global dependencies.

Basically, you cannot declare this in a .podspec file, you can have it only in a Podfile:

s.dependency 'ForkedPodName', :git => 'https://github.com/cristiangu/myforkedlib.git'

What do you do?

Add the forked lib repo as a Git Submodule in your curent repo:

  • cd <my-new-lib-podspec-root-dir>
  • git submodule add git@github.com:cristiangu/myforkedlib.git

In your .podspec file add the following:

Pod::Spec.new do |s|
    [...]
    s.dependency "ForkedPodName"
  
    s.subspec 'ForkedPodName' do |ss|
        ss.source_files = 'ForkedPodName/**/*.{swift}'
    end
end

Refresh everything with: pod install

Now your forked library (the git submodule) will be used as source_files for your ForkedPodName dependency.

Learn more about:

Feel free to write your question in the comments section bellow and let’s connect on LinkedIn.

Comments

comments powered by Disqus