CocoaPods/CocoaPods — Issue #83: Specify submodules of a project in one pod spec.
Author: alloy
Created: 2011-11-20 21:57:18+00:00
State: open

An example:

- https://github.com/CocoaPods/Specs/blob/master/RestKit/0.9.3/RestKit.podspec
- https://github.com/CocoaPods/Specs/blob/master/RestKit-Network/0.9.3/RestKit-Network.podspec
- https://github.com/CocoaPods/Specs/blob/master/RestKit-ObjectMapping/0.9.3/RestKit-ObjectMapping.podspec
- https://github.com/CocoaPods/Specs/blob/master/RestKit-XML-LibXML/0.9.3/RestKit-XML-LibXML.podspec
- https://github.com/CocoaPods/Specs/blob/master/RestKit-JSON-JSONKit/0.9.3/RestKit-JSON-JSONKit.podspec

Creating individual specs for submodules of a bigger project is currently painful. As you can see there’s a lot of repetition going on. But even worse is that if the project would add a spec to the root of their repo, so that user can install directly from it, there’s no way to list the individual components.

So all submodules of a project should be defined in one spec, something like:

```Ruby
Pod::Spec.new do |s|
s.name = 'RestKit'
s.version = '0.9.3'
s.summary = 'RestKit is a framework for consuming and modeling RESTful web resources on iOS and OS X.'
s.homepage = 'http://www.restkit.org'
s.author = { 'Blake Watters' => 'blakewatters@gmail.com' }
s.source = { :git => 'https://github.com/RestKit/RestKit.git', :tag => '0.9.3' }

# It has no source_files itself, so the resolver should not allow dependencies on this spec unless it’s a `part_of' type dependency

# This creates a new Pod::Specification instance, which has the the following attributes:
# * part_of: 'RestKit', '0.9.3'
# * name: 'RestKit/Network'
# Other attributes are delegated to the `part_of' spec, so the version, summary etc will by default be the same
s.subspec 'Network' do |ns|
ns.description = 'The network layer provides a request/response abstraction on top of NSURLConnection.'
ns.dependency 'LibComponentLogging-NSLog'
ns.source_files = 'Code/RestKit.h', 'Code/{Network,Support}/*.{h,m}'
end

# Like before, this creates a new spec with the name: RestKit/ObjectMapping and is a part of RestKit
s.subspec 'ObjectMapping' do |os|
os.description = %{The object mapping layer provides a simple API for turning remote JSON/XML responses into objects.}
os.dependency 'RestKit/Network'
os.source_files = 'Code/ObjectMapping/*.{h,m}'

# This spec will have the name: RestKit/ObjectMapping/JSON.
# Since it’s nested under another sub spec, it automatically depends on the parent: RestKit/ObjectMapping
os.subspec 'JSON' do |jos|
jos.description = 'The RestKit JSON parser which wraps JSONKit.'
jos.source_files = 'Code/Support/Parsers/JSON/RKJSONParserJSONKit.{h,m}'
jos.dependency 'JSONKit'
end

# This spec will have the name: RestKit/ObjectMapping/XML.
# Since it’s nested under another sub spec, it automatically depends on the parent: RestKit/ObjectMapping
os.subspec 'XML' do |xos|
xos.description = 'The RestKit XML parser which wraps libxml2.'
xos.source_files = 'Code/Support/Parsers/XML/RKXMLParserLibXML.{h,m}'
xos.library = 'xml2'
xos.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2' }
end
end
end
```

A Podfile for JSON ObjectMapping would then look like:

```Ruby
dependency 'RestKit/ObjectMapping/JSON'
```