Skip to content

STRUCT

Target

Contents

  • Properties
    • name
    • destinations
    • product
    • productName
    • bundleId
    • deploymentTargets
    • infoPlist
    • sources
    • resources
    • copyFiles
    • headers
    • entitlements
    • scripts
    • dependencies
    • settings
    • coreDataModels
    • environmentVariables
    • launchArguments
    • additionalFiles
    • buildRules
    • mergedBinaryType
    • mergeable
    • onDemandResourcesTags
    • metadata
    • buildableFolders
    • foreignBuild
  • Methods
    • foreignBuild(name:destinations:script:inputs:output:metadata:)
    • target(name:destinations:product:productName:bundleId:deploymentTargets:infoPlist:sources:resources:buildableFolders:copyFiles:headers:entitlements:scripts:dependencies:settings:coreDataModels:environmentVariables:launchArguments:additionalFiles:buildRules:mergedBinaryType:mergeable:onDemandResourcesTags:metadata:)
swift
public struct Target: Codable, Equatable, Sendable

A target of a project.

Properties

name

swift
public var name: String

The name of the target. Also, the product name if not specified with productName.

destinations

swift
public var destinations: Destinations

The destinations this target supports, e.g. iPhone, appleVision, macCatalyst

product

swift
public var product: Product

The type of build product this target will output.

productName

swift
public var productName: String?

The built product name. If nil, it will be equal to name.

bundleId

swift
public var bundleId: String

The product bundle identifier.

deploymentTargets

swift
public var deploymentTargets: DeploymentTargets?

The minimum deployment targets your product will support.

infoPlist

swift
public var infoPlist: InfoPlist?

The Info.plist representation.

sources

swift
public var sources: SourceFilesList?

The source files of the target. Note: any playgrounds matched by the globs used in this property will be automatically added.

resources

swift
public var resources: ResourceFileElements?

The resource files of target. Note: localizable files, *.lproj, are supported.

copyFiles

swift
public var copyFiles: [CopyFilesAction]?

The build phase copy files actions for the target.

headers

swift
public var headers: Headers?

The headers for the target.

entitlements

swift
public var entitlements: Entitlements?

The entitlements representation.

Note: For per-configuration entitlements, you should:

  1. Keep this property as nil
  2. Set the CODE_SIGN_ENTITLEMENTS build setting using Target.settings for each configuration
  3. If you want the entitlement files to be included in the project navigator, add them using Project.additionalFiles

Example:

swift
let target = Target(
    name: "MyApp",
    // ... other properties
    entitlements: nil, // Important: keep this as nil
    settings: .settings(
        configurations: [
            .debug(name: "Debug", settings: ["CODE_SIGN_ENTITLEMENTS": "Debug.entitlements"]),
            .release(name: "Release", settings: ["CODE_SIGN_ENTITLEMENTS": "Release.entitlements"])
        ]
    )
)

let project = Project(
    name: "MyProject",
    targets: [target],
    additionalFiles: [
        "Debug.entitlements",
        "Release.entitlements"
    ]
)

scripts

swift
public var scripts: [TargetScript]

The build phase scripts actions for the target.

dependencies

swift
public var dependencies: [TargetDependency]

The target's dependencies.

settings

swift
public var settings: Settings?

The target's settings.

coreDataModels

swift
public var coreDataModels: [CoreDataModel]

The Core Data models.

environmentVariables

swift
public var environmentVariables: [String: EnvironmentVariable]

The environment variables. Used by autogenerated schemes for the target.

launchArguments

swift
public var launchArguments: [LaunchArgument]

The launch arguments. Used by autogenerated schemes for the target.

additionalFiles

swift
public var additionalFiles: [FileElement]

The additional files for the target. For project's additional files, see Project/additionalFiles.

buildRules

swift
public var buildRules: [BuildRule]

The build rules used for transformation of source files during compilation.

mergedBinaryType

swift
public var mergedBinaryType: MergedBinaryType

Specifies whether if the target can merge or not the dynamic dependencies as part of its binary

mergeable

swift
public var mergeable: Bool

Specifies whether if the target can be merged as part of another binary or not

onDemandResourcesTags

swift
public var onDemandResourcesTags: OnDemandResourcesTags?

The target's tags associated with on demand resources

metadata

swift
public var metadata: TargetMetadata

The target's metadata.

buildableFolders

swift
public var buildableFolders: [BuildableFolder]

The target's buildable folders.

foreignBuild

swift
public private(set) var foreignBuild: ForeignBuild?

Properties for a foreign build target. Set when this target was created with foreignBuild(name:destinations:script:inputs:output:metadata:).

Methods

foreignBuild(name:destinations:script:inputs:output:metadata:)

swift
public static func foreignBuild(
    name: String,
    destinations: Destinations,
    script: String,
    inputs: [ForeignBuild.Input] = [],
    output: ForeignBuild.Output,
    metadata: TargetMetadata = .default
) -> Self

Creates a foreign build target that wraps a non-Xcode build system (KMP, Rust, CMake, etc.).

The target will become an aggregate target that runs the build script and produces the output binary. Other targets can depend on this target using .target(name:).

Example: Kotlin Multiplatform (KMP)

swift
.foreignBuild(
    name: "SharedKMP",
    destinations: .iOS,
    script: """
        eval "$($HOME/.local/bin/mise activate -C $SRCROOT bash --shims)"
        cd $SRCROOT/SharedKMP && gradle assembleSharedKMPReleaseXCFramework
        """,
    inputs: [
        .folder("SharedKMP/src"),
        .file("SharedKMP/build.gradle.kts"),
    ],
    output: .xcframework(
        path: "SharedKMP/build/XCFrameworks/release/SharedKMP.xcframework",
        linking: .dynamic
    )
)
  • Parameters:
    • name: A unique name for this foreign build target.
    • destinations: The destinations this target supports.
    • script: The shell script that builds the artifact. Runs in a shell build phase with $SRCROOT set to the project directory.
    • inputs: Inputs that affect the build output, used for the build phase input file list and content hashing.
    • output: The binary artifact produced by the script (.xcframework or .framework).
    • metadata: The target's metadata.

Parameters

NameDescription
nameA unique name for this foreign build target.
destinationsThe destinations this target supports.
scriptThe shell script that builds the artifact. Runs in a shell build phase with $SRCROOT set to the project directory.
inputsInputs that affect the build output, used for the build phase input file list and content hashing.
outputThe binary artifact produced by the script (.xcframework or .framework).
metadataThe target’s metadata.

target(name:destinations:product:productName:bundleId:deploymentTargets:infoPlist:sources:resources:buildableFolders:copyFiles:headers:entitlements:scripts:dependencies:settings:coreDataModels:environmentVariables:launchArguments:additionalFiles:buildRules:mergedBinaryType:mergeable:onDemandResourcesTags:metadata:)

swift
public static func target(
    name: String,
    destinations: Destinations,
    product: Product,
    productName: String? = nil,
    bundleId: String,
    deploymentTargets: DeploymentTargets? = nil,
    infoPlist: InfoPlist? = .default,
    sources: SourceFilesList? = nil,
    resources: ResourceFileElements? = nil,
    buildableFolders: [BuildableFolder] = [],
    copyFiles: [CopyFilesAction]? = nil,
    headers: Headers? = nil,
    entitlements: Entitlements? = nil,
    scripts: [TargetScript] = [],
    dependencies: [TargetDependency] = [],
    settings: Settings? = nil,
    coreDataModels: [CoreDataModel] = [],
    environmentVariables: [String: EnvironmentVariable] = [:],
    launchArguments: [LaunchArgument] = [],
    additionalFiles: [FileElement] = [],
    buildRules: [BuildRule] = [],
    mergedBinaryType: MergedBinaryType = .disabled,
    mergeable: Bool = false,
    onDemandResourcesTags: OnDemandResourcesTags? = nil,
    metadata: TargetMetadata = .default
) -> Self

Released under the MIT License.