Search code examples
iosswiftdependenciescocoapodspodspec

Add Pod dependency with source to .podspec


I am trying to add the following dependency to my Podspec

s.dependency 'Apollo/WebSocket', :git => 'https://github.com/apollographql/apollo-ios'

Here's what I get in my Terminal whenever I try to run pod lib lint MyPodName.podspec:

- ERROR | spec: The specification defined in `MyPodName.podspec` could not be loaded.


[!] Invalid `MyPodName.podspec` file: [!] Unsupported version requirements.

 #  from <PathToMyPodspec>/MyPodName.podspec:36
 #  -------------------------------------------
 #    
 >    s.dependency 'Apollo/WebSocket', :git => 'https://github.com/apollographql/apollo-ios'
 #    
 #  -------------------------------------------

I have successfully used it as a Pod in one of my iOS projects. But now that I am creating a pod myself, I am struggling to understand what I should do to make it work.

Thank you in advance!


Solution

  • Solved!

    It turns out that the Podfile document of the project plays a major role in all of this. I found it inside the /Example folder of said project. What I've done is:

    use_frameworks!
    source = 'https://github.com/apollographql/apollo-ios'
    source = 'https://github.com/apollographql/apollo-ios'
    
    target 'MyPodName_Example' do
    
      pod 'Apollo'
      pod 'Apollo/WebSocket'
      pod 'MyPodName', :path => '../'
    
      target 'MyPodName_Tests' do
        inherit! :search_paths
    
    
      end
    end
    

    (I am not quite sure if I necessarily need both of the source lines but it does work like this)

    Then I ran pod install on the /Example directory.

    After that I returned back to my MyPodName.podspec file and edited dependencies to look like this:

      s.dependency 'Apollo'
      s.dependency 'Apollo/WebSocket'
    

    Then I ran pod lib lint MyPodName.podspec on the root directory (where my .podspec file is) and this time it succeeded.


    NOTICE:

    • I needed both Apollo and Apollo/WebSocket dependencies.
    • I haven't yet pushed my Pod and cannot guarantee that all of this is 100% correct
    • I'm new to CocoaPods, so this might not be the most optimal solution to the problem.