Creating a podspec with multiple targets which have local dependencies

3.1k views Asked by At
  • I have a podspec for MyLib.
  • MyLib.xcworkspace has two targets: a MyLib target and a MySubLib target.
  • MyLib depends on MySubLib.
  • Both MyLib and MySubLib should be importable in a swift module using MyLib Cocoapod.

Illustration:

MyLib.xcworkspace

  • MyLib target <---depends on---MySubLib
    • MyLib pods dependencies
  • MySubLib target

How do we achieve this?

I have the following podspec but upon linting MySubLib is not found where it's imported in MyLib.

Pod::Spec.new do |s|
  s.name             = "MyLib"
  s.version          = "0.1"
  s.summary          = ""

  s.description      = <<-DESC

                       DESC

  s.homepage         = "https://github.com/me/MyLib"
  s.license          = 'MIT'
  s.author           = { "me" => "[email protected]" }
  s.source           = { :git => "https://github.com/me/MyLib.git", :tag => s.version.to_s }

  s.platform     = :ios, '8.0'
  s.requires_arc = true

  s.dependency 'Alamofire'

  s.source_files = 'MyLib/**/*.swift', 'MySubLib/**/*.swift'
  s.resource_bundles = {
  }

end
1

There are 1 answers

3
Adrian Bobrowski On

You can use subspec. I use it in my framework L10n-swift.

A library can specify a dependency on either another library, a subspec of another library, or a subspec of itself.

Going back to your problem

Pod::Spec.new do |s|
    s.name             = "MyLib"
    s.version          = "0.1"
    s.summary          = ""

    s.description      = <<-DESC

    DESC

    s.homepage         = "https://github.com/me/MyLib"
    s.license          = 'MIT'
    s.author           = { "me" => "[email protected]" }
    s.source           = { :git => "https://github.com/me/MyLib.git", :tag => s.version.to_s }

    s.platform     = :ios, '8.0'
    s.requires_arc = true

    s.subspec 'MySubLib' do |mySubLib|
        mySubLib.dependency 'Alamofire'
        mySubLib.source_files = 'MySubLib/**/*.swift'
    end

    s.subspec 'MyLib' do |myLib|
        myLib.dependency 'MyLib/MySubLib'
        myLib.source_files = 'MyLib/**/*.swift'
    end

    s.resource_bundles = { }
end

You can also define default_subspec

An array of subspecs names that should be used as preferred dependency. If not specified a specifications requires all its subspecs as dependencies.