How to import a Cocoapods subspec/ module instead of the entire pod in Swift

Viewed 732

A subspec "represents specification for a module of the library.".

Here's an example of a .Podspec file taken from here:

Pod::Spec.new do |s|
  s.name = 'RestKit'

  s.subspec 'Core' do |cs|
    cs.dependency 'RestKit/ObjectMapping'
    cs.dependency 'RestKit/Network'
    cs.dependency 'RestKit/CoreData'
  end

  s.subspec 'ObjectMapping' do |os|
  end
end

Inside Swift, how would someone import the only the ObjectMapping subspec, instead of the whole Cocoapos Pod? The documentation does say its a "module of the library" so this leads me to believe there is some way to import the module/ subspec individually. Unfortunately for me, maybe their definition of module is different to a Swift module and this feature doesn't exist. I am aware of only this import for the whole pod:

import RestKit
1 Answers

Not possible

This is not possible, because Podspecs define the clang module generated.

I inferred this from the module_name documentation:

The name to use for the framework / clang module which will be generated for this specification instead of the default (header_dir if set, otherwise the specification name).

...where specification means Podspec.

Workaround

Create multiple Podspec files (clang modules). You can put them in the same directory. For example, Github: mapbox/mapbox-navigation-ios has 2 podspecs in the root directory, which refer to other Podspecs elsewhere.

Related