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

Foreign Build Target

For wrapping non-Xcode build systems (KMP, Rust, CMake, etc.):

Standard Target Parameters

.target() Static Method

String
required
The name of the target. Also used as the product name if productName is not specified.
Destinations
required
The destinations this target supports (e.g., .iOS, .macOS, [.iPhone, .iPad]). See the Destinations section below.
Product
required
The type of build product this target will output. See Product Types section below.
String?
default:"nil"
The built product name. If nil, it defaults to the target name.
String
required
The product bundle identifier (e.g., “com.example.myapp”).
DeploymentTargets?
default:"nil"
The minimum deployment targets your product will support.
InfoPlist?
default:".default"
The Info.plist representation. Can be .default, .file(path:), or .dictionary(_:).
SourceFilesList?
default:"nil"
The source files of the target. Supports glob patterns. Playgrounds matched by globs are automatically added.
ResourceFileElements?
default:"nil"
The resource files of the target. Localizable files (*.lproj) are supported.
[BuildableFolder]
default:"[]"
Folders that should be built as part of the target.
[CopyFilesAction]?
default:"nil"
The build phase copy files actions for the target.
Headers?
default:"nil"
The headers for the target (public, private, and project headers).
Entitlements?
default:"nil"
The entitlements representation. For per-configuration entitlements, keep this as nil and set CODE_SIGN_ENTITLEMENTS in target settings.
[TargetScript]
default:"[]"
The build phase scripts actions for the target.
[TargetDependency]
default:"[]"
The target’s dependencies. See Dependencies API for details.
Settings?
default:"nil"
The target’s settings. See Settings API for details.
[CoreDataModel]
default:"[]"
The Core Data models.
[String: EnvironmentVariable]
default:"[:]"
The environment variables used by autogenerated schemes for the target.
[LaunchArgument]
default:"[]"
The launch arguments used by autogenerated schemes for the target.
[FileElement]
default:"[]"
The additional files for the target. For project-level additional files, see Project.additionalFiles.
[BuildRule]
default:"[]"
The build rules used for transformation of source files during compilation.
MergedBinaryType
default:".disabled"
Specifies whether the target can merge dynamic dependencies as part of its binary.
Bool
default:"false"
Specifies whether the target can be merged as part of another binary.
OnDemandResourcesTags?
default:"nil"
The target’s tags associated with on-demand resources.
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.
String
required
A unique name for this foreign build target.
Destinations
required
The destinations this target supports.
String
required
The shell script that builds the artifact. Runs with $SRCROOT set to the project directory.
[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")
ForeignBuild.Output
required
The binary artifact produced by the script.Available output types:
  • .xcframework(path: Path, linking: .static | .dynamic) - An XCFramework output
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