Skip to main content

Target

A target of a project that produces a build product.

Overview

The Target struct represents an individual build target in an Xcode project. Each target can produce a different product type (app, framework, library, etc.) and has its own sources, resources, dependencies, and build settings.

Standard Target

import ProjectDescription

let target = Target.target(
    name: "MyApp",
    destinations: .iOS,
    product: .app,
    bundleId: "com.example.myapp",
    infoPlist: .default,
    sources: ["Sources/**"],
    resources: ["Resources/**"],
    dependencies: [
        .target(name: "MyFramework"),
        .external(name: "Alamofire")
    ],
    settings: .settings(
        base: ["SWIFT_VERSION": "5.9"],
        configurations: [
            .debug(name: "Debug"),
            .release(name: "Release")
        ]
    )
)

Foreign Build Target

For wrapping non-Xcode build systems (KMP, Rust, CMake, etc.):
let kmpTarget = Target.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
    )
)

Standard Target Parameters

.target() Static Method

name
String
required
The name of the target. Also used as the product name if productName is not specified.
destinations
Destinations
required
The destinations this target supports (e.g., .iOS, .macOS, [.iPhone, .iPad]). See the Destinations section below.
product
Product
required
The type of build product this target will output. See Product Types section below.
productName
String?
default:"nil"
The built product name. If nil, it defaults to the target name.
bundleId
String
required
The product bundle identifier (e.g., “com.example.myapp”).
deploymentTargets
DeploymentTargets?
default:"nil"
The minimum deployment targets your product will support.
infoPlist
InfoPlist?
default:".default"
The Info.plist representation. Can be .default, .file(path:), or .dictionary(_:).
sources
SourceFilesList?
default:"nil"
The source files of the target. Supports glob patterns. Playgrounds matched by globs are automatically added.
resources
ResourceFileElements?
default:"nil"
The resource files of the target. Localizable files (*.lproj) are supported.
buildableFolders
[BuildableFolder]
default:"[]"
Folders that should be built as part of the target.
copyFiles
[CopyFilesAction]?
default:"nil"
The build phase copy files actions for the target.
headers
Headers?
default:"nil"
The headers for the target (public, private, and project headers).
entitlements
Entitlements?
default:"nil"
The entitlements representation. For per-configuration entitlements, keep this as nil and set CODE_SIGN_ENTITLEMENTS in target settings.
scripts
[TargetScript]
default:"[]"
The build phase scripts actions for the target.
dependencies
[TargetDependency]
default:"[]"
The target’s dependencies. See Dependencies API for details.
settings
Settings?
default:"nil"
The target’s settings. See Settings API for details.
coreDataModels
[CoreDataModel]
default:"[]"
The Core Data models.
environmentVariables
[String: EnvironmentVariable]
default:"[:]"
The environment variables used by autogenerated schemes for the target.
launchArguments
[LaunchArgument]
default:"[]"
The launch arguments used by autogenerated schemes for the target.
additionalFiles
[FileElement]
default:"[]"
The additional files for the target. For project-level additional files, see Project.additionalFiles.
buildRules
[BuildRule]
default:"[]"
The build rules used for transformation of source files during compilation.
mergedBinaryType
MergedBinaryType
default:".disabled"
Specifies whether the target can merge dynamic dependencies as part of its binary.
mergeable
Bool
default:"false"
Specifies whether the target can be merged as part of another binary.
onDemandResourcesTags
OnDemandResourcesTags?
default:"nil"
The target’s tags associated with on-demand resources.
metadata
TargetMetadata
default:".default"
The target’s metadata.

Foreign Build Parameters

.foreignBuild() Static Method

Wraps non-Xcode build systems like Kotlin Multiplatform (KMP), Rust, or CMake.
name
String
required
A unique name for this foreign build target.
destinations
Destinations
required
The destinations this target supports.
script
String
required
The shell script that builds the artifact. Runs with $SRCROOT set to the project directory.
inputs
[ForeignBuild.Input]
default:"[]"
Inputs that affect the build output, used for the build phase input file list and content hashing.Available input types:
  • .file(Path) - A single file whose contents affect the build output
  • .folder(Path) - A folder whose contents (recursively) affect the build output
  • .glob(Path) - A glob pattern that resolves to files
  • .script(String) - A shell script whose stdout produces a cache key component (e.g., "git rev-parse HEAD")
output
ForeignBuild.Output
required
The binary artifact produced by the script.Available output types:
  • .xcframework(path: Path, linking: .static | .dynamic) - An XCFramework output
metadata
TargetMetadata
default:".default"
The target’s metadata.

Product Types

Available product types for the product parameter:
  • .app - An application
  • .staticLibrary - A static library
  • .dynamicLibrary - A dynamic library
  • .framework - A dynamic framework
  • .staticFramework - A static framework
  • .unitTests - A unit tests bundle
  • .uiTests - A UI tests bundle
  • .bundle - A custom bundle (currently only iOS resource bundles)
  • .commandLineTool - A command line tool (macOS only)
  • .appClip - An App Clip (iOS only)
  • .appExtension - An application extension
  • .watch2App - A Watch application (watchOS only)
  • .watch2Extension - A Watch application extension (watchOS only)
  • .tvTopShelfExtension - A TV Top Shelf Extension
  • .messagesExtension - An iMessage extension (iOS only)
  • .stickerPackExtension - A sticker pack extension
  • .xpc - An XPC service (macOS only)
  • .systemExtension - A system extension (macOS only)
  • .extensionKitExtension - An ExtensionKit extension
  • .macro - A Swift Macro

Destinations

Destinations specify which Apple platforms and device types the target supports:

Platform Convenience Sets

  • .iOS - [.iPhone, .iPad, .macWithiPadDesign]
  • .macOS - [.mac]
  • .tvOS - [.appleTv]
  • .watchOS - [.appleWatch]
  • .visionOS - [.appleVision]

Individual Destinations

  • .iPhone - iPhone support
  • .iPad - iPad support
  • .mac - Native macOS support
  • .macWithiPadDesign - macOS using iPad design
  • .macCatalyst - Mac Catalyst support
  • .appleWatch - watchOS support
  • .appleTv - tvOS support
  • .appleVision - visionOS support
  • .appleVisionWithiPadDesign - visionOS using iPad design