module Pod::Specification::DSL
A specification describes a version of Pod
library. It includes details about where the source should be fetched from, what files to use, the build settings to apply, and other general metadata such as its name, version, and description.
A stub specification file can be generated by the [pod spec create](guides.cocoapods.org/terminal/commands.html#pod_spec_create) command.
The specification DSL
provides great flexibility and dynamism. Moreover, the DSL
adopts the [convention over configuration](en.wikipedia.org/wiki/Convention_over_configuration) and thus it can be very simple:
Pod::Spec.new do |spec| spec.name = 'Reachability' spec.version = '3.1.0' spec.license = { :type => 'BSD' } spec.homepage = 'https://github.com/tonymillion/Reachability' spec.authors = { 'Tony Million' => 'tonymillion@gmail.com' } spec.summary = 'ARC and GCD Compatible Reachability Class for iOS and OS X.' spec.source = { :git => 'https://github.com/tonymillion/Reachability.git', :tag => 'v3.1.0' } spec.source_files = 'Reachability.{h,m}' spec.framework = 'SystemConfiguration' end
Or it can be quite detailed:
Pod::Spec.new do |spec| spec.name = 'Reachability' spec.version = '3.1.0' spec.license = { :type => 'BSD' } spec.homepage = 'https://github.com/tonymillion/Reachability' spec.authors = { 'Tony Million' => 'tonymillion@gmail.com' } spec.summary = 'ARC and GCD Compatible Reachability Class for iOS and OS X.' spec.source = { :git => 'https://github.com/tonymillion/Reachability.git', :tag => 'v3.1.0' } spec.module_name = 'Rich' spec.swift_version = '4.0' spec.ios.deployment_target = '9.0' spec.osx.deployment_target = '10.10' spec.source_files = 'Reachability/common/*.swift' spec.ios.source_files = 'Reachability/ios/*.swift', 'Reachability/extensions/*.swift' spec.osx.source_files = 'Reachability/osx/*.swift' spec.framework = 'SystemConfiguration' spec.ios.framework = 'UIKit' spec.osx.framework = 'AppKit' spec.dependency 'SomeOtherPod' end
Constants
- ALL_SCRIPT_PHASE_KEYS
- EXECUTION_POSITION_KEYS
- LICENSE_KEYS
The keys accepted by the license attribute.
- ON_DEMAND_RESOURCES_CATEGORY_KEYS
The keys accepted by the category attribute for each on demand resource entry.
- PLATFORMS
The names of the platforms supported by the specification class.
- SCHEME_KEYS
- SCRIPT_PHASE_OPTIONAL_KEYS
- SCRIPT_PHASE_REQUIRED_KEYS
- SOURCE_KEYS
The keys accepted by the hash of the source attribute.
- SUPPORTED_TEST_TYPES
The list of the test types currently supported.
Attributes
Public Instance Methods
Represents an app specification for the library. Here you can place all your app source files for your podspec along with the app dependencies.
@example
Pod::Spec.new do |spec| spec.name = 'NSAttributedString+CCLFormat' spec.app_spec do |app_spec| app_spec.source_files = 'NSAttributedString+CCLFormat.m' app_spec.dependency 'AFNetworking' end end
# File lib/cocoapods-core/specification/dsl.rb, line 1783 def app_spec(name = 'App', &block) appspec = Specification.new(self, name, :app_specification => true, &block) @subspecs << appspec appspec end
Any dependency on other Pods or to a ‘sub-specification’.
Dependencies can specify versions requirements. The use of the optimistic version indicator ‘~>` is recommended because it provides good control over the version without being too restrictive. For example, `~> 1.0.1` is equivalent to `>= 1.0.1` combined with `< 1.1`. Similarly, `~> 1.0` will match `1.0`, `1.0.1`, `1.1`, but will not upgrade to `2.0`.
Pods with overly restrictive dependencies limit their compatibility with other Pods.
@example
spec.dependency 'AFNetworking', '~> 1.0'
@example
spec.dependency 'AFNetworking', '~> 1.0', :configurations => ['Debug']
@example
spec.dependency 'AFNetworking', '~> 1.0', :configurations => :debug
@example
spec.dependency 'RestKit/CoreData', '~> 0.20.0'
@example
spec.ios.dependency 'MBProgressHUD', '~> 0.5'
# File lib/cocoapods-core/specification/dsl.rb, line 697 def dependency(*args) name, *version_requirements = args if name == self.name raise Informative, "A specification can't require itself as a " \ 'subspec' end if @parent composed_name = '' @parent.name.split('/').each do |component| composed_name << component if name == composed_name raise Informative, "A subspec can't require one of its " \ 'parents specifications' else composed_name << '/' end end end configurations_option = version_requirements.find { |option| option.is_a?(Hash) && option.key?(:configurations) } whitelisted_configurations = if configurations_option version_requirements.delete(configurations_option) Array(configurations_option.delete(:configurations)).map { |c| c.to_s.downcase } end dependency_options = version_requirements.reject { |req| req.is_a?(String) } dependency_options.each do |dependency_option| if dependency_option.is_a?(Hash) if !dependency_option[:path].nil? raise Informative, 'Podspecs cannot specify the source of dependencies. The `:path` option is not supported.'\ ' `:path` can be used in the Podfile instead to override global dependencies.' elsif !dependency_option[:git].nil? raise Informative, '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.' end end raise Informative, "Unsupported version requirements. #{version_requirements.inspect} is not valid." end attributes_hash['dependencies'] ||= {} attributes_hash['dependencies'][name] = version_requirements unless whitelisted_configurations.nil? if (extras = whitelisted_configurations - %w(debug release)) && !extras.empty? raise Informative, "Only `Debug` & `Release` are allowed under configurations for dependency on `#{name}`. " \ "Found #{extras.map { |configuration| "`#{configuration}`" }.to_sentence}." end attributes_hash['configuration_pod_whitelist'] ||= {} attributes_hash['configuration_pod_whitelist'][name] = whitelisted_configurations end end
# File lib/cocoapods-core/specification/dsl.rb, line 750 def dependency=(args) joined = args.join('\', \'') arguments = "\'#{joined}\'" raise Informative, "Cannot assign value to `dependency`. Did you mean: `dependency #{arguments}`?" end
The minimum deployment targets of the supported platforms.
As opposed to the ‘platform` attribute, the `deployment_target` attribute allows to specify multiple platforms on which this pod is supported — specifying a different deployment target for each.
@example
spec.ios.deployment_target = '6.0'
@example
spec.osx.deployment_target = '10.8'
@param [String] _args
The deployment target of the platform.
# File lib/cocoapods-core/specification/dsl.rb, line 646 def deployment_target=(*_args) raise Informative, 'The deployment target can be declared only per ' \ 'platform.' end
Provides support for specifying iOS attributes.
@example
spec.ios.source_files = 'Classes/ios/**/*.{h,m}'
@return [PlatformProxy] the proxy that will set the attributes.
# File lib/cocoapods-core/specification/dsl.rb, line 1855 def ios PlatformProxy.new(self, :ios) end
Provides support for specifying OS X attributes.
@example
spec.osx.source_files = 'Classes/osx/**/*.{h,m}'
@return [PlatformProxy] the proxy that will set the attributes.
# File lib/cocoapods-core/specification/dsl.rb, line 1866 def osx PlatformProxy.new(self, :osx) end
The platform on which this Pod
is supported. Leaving this blank means the Pod
is supported on all platforms. When supporting multiple platforms you should use deployment_target below instead.
@example
spec.platform = :osx, '10.8'
@example
spec.platform = :ios
@example
spec.platform = :osx
@param [Array<Symbol, String>] args
A tuple where the first value is the name of the platform, (either `:ios` or `:osx`) and the second is the deployment target.
# File lib/cocoapods-core/specification/dsl.rb, line 617 def platform=(args) name, deployment_target = args name = :osx if name.to_s == 'macos' attributes_hash['platforms'] = if name { name.to_s => deployment_target } else {} end end
Represents specification for a module of the library.
Subspecs participate on a dual hierarchy.
On one side, a specification automatically inherits as a dependency all it children ‘sub-specifications’ (unless a default subspec is specified).
On the other side, a ‘sub-specification’ inherits the value of the attributes of the parents so common values for attributes can be specified in the ancestors.
Although it sounds complicated in practice it means that subspecs in general do what you would expect:
pod 'ShareKit', '2.0'
Installs ShareKit with all the sharers like ‘ShareKit/Evernote`, `ShareKit/Facebook`, etc, as they are defined as subspecs.
pod 'ShareKit/Twitter', '2.0' pod 'ShareKit/Pinboard', '2.0'
Installs ShareKit with only the source files for ‘ShareKit/Twitter`, `ShareKit/Pinboard`. Note that, in this case, the ‘sub-specifications’to compile need the source files, the dependencies, and the other attributes defined by the root specification. CocoaPods is smart enough to handle any issues arising from duplicate attributes.
@example Subspecs with different source files.
subspec 'Twitter' do |sp| sp.source_files = 'Classes/Twitter' end subspec 'Pinboard' do |sp| sp.source_files = 'Classes/Pinboard' end
@example Subspecs referencing dependencies to other subspecs.
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
@example Nested subspecs.
Pod::Spec.new do |s| s.name = 'Root' s.subspec 'Level_1' do |sp| sp.subspec 'Level_2' do |ssp| end end end
# File lib/cocoapods-core/specification/dsl.rb, line 1642 def subspec(name, &block) subspec = Specification.new(self, name, &block) @subspecs << subspec subspec end
Represents a test specification for the library. Here you can place all your tests for your podspec along with the test dependencies.
@example
Pod::Spec.new do |spec| spec.name = 'NSAttributedString+CCLFormat' spec.test_spec do |test_spec| test_spec.source_files = 'NSAttributedString+CCLFormatTests.m' test_spec.dependency 'Expecta' end end
# File lib/cocoapods-core/specification/dsl.rb, line 1761 def test_spec(name = 'Tests', &block) subspec = Specification.new(self, name, true, &block) @subspecs << subspec subspec end
Provides support for specifying tvOS attributes.
@example
spec.tvos.source_files = 'Classes/tvos/**/*.{h,m}'
@return [PlatformProxy] the proxy that will set the attributes.
# File lib/cocoapods-core/specification/dsl.rb, line 1879 def tvos PlatformProxy.new(self, :tvos) end
Provides support for specifying visionOS attributes.
@example
spec.visionos.source_files = 'Classes/visionos/**/*.{h,m}'
@return [PlatformProxy] the proxy that will set the attributes.
# File lib/cocoapods-core/specification/dsl.rb, line 1890 def visionos PlatformProxy.new(self, :visionos) end
Provides support for specifying watchOS attributes.
@example
spec.watchos.source_files = 'Classes/watchos/**/*.{h,m}'
@return [PlatformProxy] the proxy that will set the attributes.
# File lib/cocoapods-core/specification/dsl.rb, line 1901 def watchos PlatformProxy.new(self, :watchos) end