Method: Pod::Podfile::DSL#pod
- Defined in:
- lib/cocoapods-core/podfile/dsl.rb
#pod(name = nil, *requirements) ⇒ void
This method allow a nil name and the raises to be more informative.
This method returns an undefined value.
Specifies a dependency of the project.
A dependency requirement is defined by the name of the Pod and optionally a list of version requirements.
When starting out with a project it is likely that you will want to use the latest version of a Pod. If this is the case, simply omit the version requirements.
pod 'SSZipArchive'
Later on in the project you may want to freeze to a specific version of a Pod, in which case you can specify that version number.
pod 'Objection', '0.9'
Besides no version, or a specific one, it is also possible to use operators:
= 0.1Version 0.1.> 0.1Any version higher than 0.1.>= 0.1Version 0.1 and any higher version.< 0.1Any version lower than 0.1.<= 0.1Version 0.1 and any lower version.~> 0.1.2Version 0.1.2 and the versions up to 0.2, not including 0.2. This operator works based on the last component that you specify in your version requirement. The example is equal to>= 0.1.2combined with< 0.2.0and will always match the latest known version matching your requirements.~> 0Version 0 and the versions up to 1, not including 1.~> 0.1.3-beta.0Beta and release versions for 0.1.3, release versions up to 0.2 excluding 0.2. Components separated by a dash (-) will not be considered for the version requirement.
A list of version requirements can be specified for even more fine grained control.
For more information, regarding versioning policy, see:
Build configurations
By default dependencies are installed in all the build configurations of the target. For debug purposes or for other reasons, they can be only enabled on a list of build configurations.
pod 'PonyDebugger', :configurations => ['Debug', 'Beta']
Alternatively, you can specify to have it included on a single build configuration.
pod 'PonyDebugger', :configuration => 'Debug'
Note that transitive dependencies are included in all configurations and you have to manually specify build configurations for them as well in case this is not desired.
Modular Headers
If you would like to use modular headers per Pod you can use the following syntax:
pod 'SSZipArchive', :modular_headers => true
Additionally, when you use the use_modular_headers! attribute,
you can exclude a particular Pod from modular headers using the following:
pod 'SSZipArchive', :modular_headers => false
Source
By default the sources specified at the global level are searched in the order they are specified for a dependency match. This behaviour can be altered for a specific dependency by specifying the source with the dependency:
pod 'PonyDebugger', :source => 'https://cdn.cocoapods.org/'
In this case only the specified source will be searched for the dependency and any global sources ignored.
Subspecs
When installing a Pod via its name, it will install all of the default subspecs defined in the podspec.
You may install a specific subspec using the following:
pod 'QueryKit/Attribute'
You may specify a collection of subspecs to be installed as follows:
pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']
Test Specs
Test specs can be optionally included via the :testspecs option. By default,
none of a Pod's test specs are included.
You may specify a list of test spec names to install using the following:
pod 'AFNetworking', :testspecs => ['UnitTests', 'SomeOtherTests']
The values provided to :testspecs correspond to the name provided to the
test_spec DSL attribute in a Podspec.
Dependencies can be obtained also from external sources.
Using the files from a local path.
If you would like to use develop a Pod in tandem with its client
project you can use the path option.
pod 'AFNetworking', :path => '~/Documents/AFNetworking'
Using this option CocoaPods will assume the given folder to be the root of the Pod and will link the files directly from there in the Pods project. This means that your edits will persist to CocoaPods installations.
The referenced folder can be a checkout of your your favourite SCM or even a git submodule of the current repository.
Note that the podspec of the Pod file is expected to be in the
folder.
From a podspec in the root of a library repository.
Sometimes you may want to use the bleeding edge version of a Pod. Or a specific revision. If this is the case, you can specify that with your pod declaration.
To use the master branch of the repository:
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git'
To use a different branch of the repository:
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :branch => 'dev'
To use a tag of the repository:
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '0.7.0'
Or specify a commit:
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af'
It is important to note, though, that this means that the version will have to satisfy any other dependencies on the Pod by other Pods.
The podspec file is expected to be in the root of the repository,
if this library does not have a podspec file in its repository
yet, you will have to use one of the approaches outlined in the
sections below.
From a podspec outside a spec repository, for a library without podspec.
If a podspec is available from another source outside of the library’s repository. Consider, for instance, a podspec available via HTTP:
pod 'JSONKit', :podspec => 'https://example.com/JSONKit.podspec'
301 302 303 304 305 306 307 |
# File 'lib/cocoapods-core/podfile/dsl.rb', line 301 def pod(name = nil, *requirements) unless name raise StandardError, 'A dependency requires a name.' end current_target_definition.store_pod(name, *requirements) end |