Module: Pod::Podfile::DSL

Included in:
Pod::Podfile
Defined in:
lib/cocoapods-core/podfile/dsl.rb

Overview

The Podfile is a specification that describes the dependencies of the targets of one or more Xcode projects. The Podfile always creates an implicit target, named default, which links to the first target of the user project.

A Podfile can be very simple:

source 'https://github.com/CocoaPods/Specs.git'
pod 'AFNetworking', '~> 1.0'

An example of a more complex Podfile can be:

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '6.0'
inhibit_all_warnings!

xcodeproj 'MyProject'

pod 'ObjectiveSugar', '~> 0.5'

target :test do
  pod 'OCMock', '~> 2.0.1'
end

post_install do |installer|
  installer.project.targets.each do |target|
    puts "#{target.name}"
  end
end

Dependencies The Podfile specifies the dependencies of each user target. * `pod` is the way to declare a specific dependency. * `podspec` provides an easy API for the creation of podspecs. * `target` allows you to scope your dependencies to specific targets in your Xcode projects. collapse

Target configuration These settings are used to control the CocoaPods generated project. This starts out simply with stating what `platform` you are working on. `xcodeproj` allows you to state specifically which project to link with. collapse

Workspace This group list the options to configure workspace and to set global settings. collapse

Sources The Podfile retrieves specs from a given list of sources (repositories). Sources are __global__ and they are not stored per target definition. collapse

Hooks The Podfile provides hooks that will be called during the installation process. Hooks are __global__ and not stored per target definition. collapse

Instance Method Details

#generate_bridge_support!void

This method returns an undefined value.

Specifies that a BridgeSupport metadata document should be generated from the headers of all installed Pods.


This is for scripting languages such as MacRuby, Nu, and JSCocoa, which use it to bridge types, functions, etc.


486
487
488
# File 'lib/cocoapods-core/podfile/dsl.rb', line 486

def generate_bridge_support!
  set_hash_value('generate_bridge_support', true)
end

#inhibit_all_warnings!Object

Inhibits all the warnings from the CocoaPods libraries.


This attribute is inherited by child target definitions.

If you would like to inhibit warnings per Pod you can use the following syntax:

pod 'SSZipArchive', :inhibit_warnings => true

430
431
432
# File 'lib/cocoapods-core/podfile/dsl.rb', line 430

def inhibit_all_warnings!
  current_target_definition.inhibit_all_warnings = true
end

This method returns an undefined value.

Specifies the target(s) in the user’s project that this Pods library should be linked in.


If no explicit target is specified, then the Pods target will be linked with the first target in your project. So if you only have one target you do not need to specify the target to link with.

Examples:

Link with a user project target


link_with 'MyApp'

Link with multiple user project targets


link_with 'MyApp', 'MyOtherApp'

Parameters:

  • targets (String, Array<String>)

    the target or the targets to link with.


415
416
417
# File 'lib/cocoapods-core/podfile/dsl.rb', line 415

def link_with(*targets)
  current_target_definition.link_with = targets.flatten
end

#platform(name, target = nil) ⇒ void

This method returns an undefined value.

Specifies the platform for which a static library should be built.

CocoaPods provides a default deployment target if one is not specified. The current default values are 4.3 for iOS, 10.6 for OS X and 2.0 for watchOS.

If the deployment target requires it (iOS < 4.3), armv6 architecture will be added to ARCHS.

Examples:

Specifying the platform


platform :ios, "4.0"
platform :ios

Parameters:

  • name (Symbol)

    the name of platform, can be either :osx for OS X, :ios for iOS or :watchos for watchOS.

  • target (String, Version) (defaults to: nil)

    The optional deployment. If not provided a default value according to the platform name will be assigned.


337
338
339
340
341
# File 'lib/cocoapods-core/podfile/dsl.rb', line 337

def platform(name, target = nil)
  # Support for deprecated options parameter
  target = target[:deployment_target] if target.is_a?(Hash)
  current_target_definition.set_platform(name, target)
end

#plugin(name, options = {}) ⇒ void

This method returns an undefined value.

Specifies the plugins that should be used during installation.


Use this method to specify a plugin that should be used during installation, along with the options that should be passed to the plugin when it is invoked.

Examples:

Specifying to use the slather and cocoapods-keys plugins.


plugin 'cocoapods-keys', :keyring => 'Eidolon'
plugin 'slather'

Parameters:

  • name (String)

    The name of the plugin.

  • options (Hash) (defaults to: {})

    The optional options that should be passed to the plugin when its hooks are invoked.


576
577
578
579
580
# File 'lib/cocoapods-core/podfile/dsl.rb', line 576

def plugin(name, options = {})
  hash_plugins = get_hash_value('plugins') || {}
  (hash_plugins[name] ||= {}).merge!(options.deep_stringify_keys)
  set_hash_value('plugins', hash_plugins)
end

#pod(name = nil, *requirements, &block) ⇒ void

Note:

This method allow a nil name and the raises to be more informative.

Note:

Support for inline podspecs has been deprecated.

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.1 Any version higher than 0.1.
  • >= 0.1 Version 0.1 and any higher version.
  • < 0.1 Any version lower than 0.1.
  • <= 0.1 Version 0.1 and any lower version.
  • ~> 0.1.2 Version 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.2 combined with < 0.2.0 and will always match the latest known version matching your requirements.

A list of version requirements can be specified for even more fine grained control.

For more information, regarding versioning policy, see:

Finally, instead of a version, you can specify the :head flag. This will use the spec of the newest available version in your spec repo(s), but force the download of the ‘bleeding edge’ version (HEAD). Use this with caution, as the spec might not be compatible anymore.

pod 'Objection', :head

Build configurations

IMPORTANT: the following syntax is tentative and might change without notice in future. This feature is released in this state due to the strong demand for it. You can use it but you might need to change your Podfile to use future versions of CocoaPods. Anyway a clear and simple upgrade path will be provided.

By default dependencies are installed on all the build configurations of the target. For debug purposes or for other reasons, they can be enabled only on a given list of build configuration names.

pod 'PonyDebugger', :configurations => ['Release', 'App Store']

Alternatively you can white-list only a single build configuration.

pod 'PonyDebugger', :configuration => ['Release']

Subspecs

When installing a Pod via it's 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']

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'

201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/cocoapods-core/podfile/dsl.rb', line 201

def pod(name = nil, *requirements, &block)
  if block
    raise StandardError, 'Inline specifications are deprecated. ' \
      'Please store the specification in a `podspec` file.'
  end

  unless name
    raise StandardError, 'A dependency requires a name.'
  end

  current_target_definition.store_pod(name, *requirements)
end

#podspec(options = nil) ⇒ void

Note:

This method uses the dependencies declared by the for the platform of the target definition.

Note:

This method requires that the Podfile has a non nil value for Pod::Podfile#defined_in_file unless the path option is used.

This method returns an undefined value.

Use the dependencies of a Pod defined in the given podspec file. If no arguments are passed the first podspec in the root of the Podfile is used. It is intended to be used by the project of a library. Note: this does not include the sources derived from the podspec just the CocoaPods infrastructure.

Examples:

podspec
podspec :name => 'QuickDialog'
podspec :path => '/Documents/PrettyKit/PrettyKit.podspec'

Parameters:

  • options (Hash {Symbol=>String}) (defaults to: nil)

    the path where to load the Specification. If not provided the first podspec in the directory of the Podfile is used.

Options Hash (options):

  • :path (String)

    the path of the podspec file

  • :name (String)

    the name of the podspec


248
249
250
# File 'lib/cocoapods-core/podfile/dsl.rb', line 248

def podspec(options = nil)
  current_target_definition.store_podspec(options)
end

#post_install(&block) ⇒ void

This method returns an undefined value.

This hook allows you to make any last changes to the generated Xcode project before it is written to disk, or any other tasks you might want to perform.

It receives the Pod::Installer as its only argument.

Examples:

Customising the build settings of all targets


post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['GCC_ENABLE_OBJC_GC'] = 'supported'
    end
  end
end

620
621
622
# File 'lib/cocoapods-core/podfile/dsl.rb', line 620

def post_install(&block)
  @post_install_callback = block
end

#pre_install(&block) ⇒ Object

This hook allows you to make any changes to the Pods after they have been downloaded but before they are installed.

It receives the Pod::Installer as its only argument.

Examples:

Defining a pre install hook in a Podfile.


pre_install do |installer|
  # Do something fancy!
end

596
597
598
# File 'lib/cocoapods-core/podfile/dsl.rb', line 596

def pre_install(&block)
  @pre_install_callback = block
end

#set_arc_compatibility_flag!void

This method returns an undefined value.

Specifies that the -fobjc-arc flag should be added to the OTHER_LD_FLAGS.


This is used as a workaround for a compiler bug with non-ARC projects (see #142). This was originally done automatically but libtool as of Xcode 4.3.2 no longer seems to support the -fobjc-arc flag. Therefore it now has to be enabled explicitly using this method.

Support for this method might be dropped in CocoaPods 1.0.


504
505
506
# File 'lib/cocoapods-core/podfile/dsl.rb', line 504

def set_arc_compatibility_flag!
  set_hash_value('set_arc_compatibility_flag', true)
end

#source(source) ⇒ void

This method returns an undefined value.

Specifies the location of specs


Use this method to specify sources. The order of the sources is relevant. CocoaPods will use the highest version of a Pod of the first source which includes the Pod (regardless whether other sources have a higher version).

Examples:

Specifying to first use the Artsy repository and then the

CocoaPods Master Repository

source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'

Parameters:

  • source (String)

    The URL of a specs repository.


538
539
540
541
542
# File 'lib/cocoapods-core/podfile/dsl.rb', line 538

def source(source)
  hash_sources = get_hash_value('sources') || []
  hash_sources << source
  set_hash_value('sources', hash_sources.uniq)
end

#target(name, options = {}) ⇒ void

This method returns an undefined value.

Defines a new static library target and scopes dependencies defined from the given block. The target will by default include the dependencies defined outside of the block, unless the :exclusive => true option is given.


The Podfile creates a global target named :default which produces the libPods.a file. This target is linked with the first target of user project if not value is specified for the link_with attribute.

Examples:

Defining a target


target :ZipApp do
  pod 'SSZipArchive'
end

Defining an exclusive target


target :ZipApp do
  pod 'SSZipArchive'
  target :test, :exclusive => true do
    pod 'JSONKit'
  end
end

Parameters:

  • name (Symbol, String)

    the name of the target definition.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :exclusive (Bool)

    whether the target should inherit the dependencies of its parent. by default targets are inclusive.


288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/cocoapods-core/podfile/dsl.rb', line 288

def target(name, options = {})
  if options && !options.keys.all? { |key| [:exclusive].include?(key) }
    raise Informative, "Unsupported options `#{options}` for " \
      "target `#{name}`"
  end

  parent = current_target_definition
  definition = TargetDefinition.new(name, parent)
  definition.exclusive = true if options[:exclusive]
  self.current_target_definition = definition
  yield
ensure
  self.current_target_definition = parent
end

#use_frameworks!(flag = true) ⇒ Object

Use frameworks instead of static libraries for Pods.


This attribute is inherited by child target definitions.


440
441
442
# File 'lib/cocoapods-core/podfile/dsl.rb', line 440

def use_frameworks!(flag = true)
  current_target_definition.use_frameworks!(flag)
end

#workspace(path) ⇒ void

This method returns an undefined value.

Specifies the Xcode workspace that should contain all the projects.


If no explicit Xcode workspace is specified and only one project exists in the same directory as the Podfile, then the name of that project is used as the workspace’s name.

Examples:

Specifying a workspace


workspace 'MyWorkspace'

Parameters:

  • path (String)

    path of the workspace.


470
471
472
# File 'lib/cocoapods-core/podfile/dsl.rb', line 470

def workspace(path)
  set_hash_value('workspace', path.to_s)
end

#xcodeproj(path, build_configurations = {}) ⇒ void

This method returns an undefined value.

Specifies the Xcode project that contains the target that the Pods library should be linked with.


If no explicit project is specified, it will use the Xcode project of the parent target. If none of the target definitions specify an explicit project and there is only one project in the same directory as the Podfile then that project will be used.

It is possible also to specify whether the build settings of your custom build configurations should be modelled after the release or the debug presets. To do so you need to specify a hash where the name of each build configuration is associated to either :release or :debug.

Examples:

Specifying the user project


# Look for target to link with in an Xcode project called
# `MyProject.xcodeproj`.
xcodeproj 'MyProject'

target :test do
  # This Pods library links with a target in another project.
  xcodeproj 'TestProject'
end

Using custom build configurations


xcodeproj 'TestProject', 'Mac App Store' => :release, 'Test' => :debug

Parameters:

  • path (String)

    the path of the project to link with

  • build_configurations (Hash{String => symbol}) (defaults to: {})

    a hash where the keys are the name of the build configurations in your Xcode project and the values are Symbols that specify if the configuration should be based on the :debug or :release configuration. If no explicit mapping is specified for a configuration in your project, it will default to :release.


388
389
390
391
# File 'lib/cocoapods-core/podfile/dsl.rb', line 388

def xcodeproj(path, build_configurations = {})
  current_target_definition.user_project_path = path
  current_target_definition.build_configurations = build_configurations
end