Method: Pod::Podfile::DSL#target

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

#target(name, options = nil) ⇒ void

This method returns an undefined value.

Defines a CocoaPods target and scopes dependencies defined within the given block. A target should correspond to an Xcode target. By default the target includes the dependencies defined outside of the block, unless instructed not to inherit! them.

Examples:

Defining a target


target 'ZipApp' do
  pod 'SSZipArchive'
end

Defining a test target accessing SSZipArchive pod from its parent


target 'ZipApp' do
  pod 'SSZipArchive'

  target 'ZipAppTests' do
    inherit! :search_paths
    pod 'Nimble'
  end
end

Defining a target applies Pods to multiple targets via its parent target


target 'ShowsApp' do
  pod 'ShowsKit'

  # Has its own copy of ShowsKit + ShowTVAuth
  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end

  # Has its own copy of Specta + Expecta
  # and has access to ShowsKit via the app
  # that the test target is bundled into

  target 'ShowsTests' do
    inherit! :search_paths
    pod 'Specta'
    pod 'Expecta'
  end
end

Parameters:

  • name (Symbol, String)

    the name of the target.



395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/cocoapods-core/podfile/dsl.rb', line 395

def target(name, options = nil)
  if options
    raise Informative, "Unsupported options `#{options}` for " \
      "target `#{name}`."
  end

  parent = current_target_definition
  definition = TargetDefinition.new(name, parent)
  self.current_target_definition = definition
  yield if block_given?
ensure
  self.current_target_definition = parent
end