Method: Xcodeproj::Project::ProjectHelper.new_target

Defined in:
lib/xcodeproj/project/project_helper.rb

.new_target(project, type, name, platform, deployment_target, product_group, language, product_basename) ⇒ PBXNativeTarget

Creates a new target and adds it to the project.

The target is configured for the given platform and its file reference it is added to the Xcodeproj::Project#products_group.

The target is pre-populated with common build settings, and the appropriate Framework according to the platform is added to to its Frameworks phase.

Parameters:

  • project (Project)

    the project to which the target should be added.

  • type (Symbol)

    the type of target. Can be :application, :dynamic_library, framework or :static_library.

  • name (String)

    the name of the target product.

  • platform (Symbol)

    the platform of the target. Can be :ios or :osx.

  • deployment_target (String)

    the deployment target for the platform.

  • product_group (PBXGroup)

    the product group, where to add to a file reference of the created target.

  • language (Symbol)

    the primary language of the target, can be :objc or :swift.

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/xcodeproj/project/project_helper.rb', line 44

def self.new_target(project, type, name, platform, deployment_target, product_group, language, product_basename)
  # Target
  target = project.new(PBXNativeTarget)
  project.targets << target
  target.name = name
  target.product_name = product_basename
  target.product_type = Constants::PRODUCT_TYPE_UTI[type]
  target.build_configuration_list = configuration_list(project, platform, deployment_target, type, language)

  # Product
  product = product_group.new_product_ref_for_target(target.product_name, type)
  target.product_reference = product

  # Build phases
  build_phases_for_target_type(type).each { |phase| target.build_phases << project.new(phase) }

  # Frameworks
  unless type == :static_library
    framework_name = (platform == :osx) ? 'Cocoa' : 'Foundation'
    target.add_system_framework(framework_name)
  end

  target
end