STRUCT
Target
Contents
- Properties
namedestinationsproductproductNamebundleIddeploymentTargetsinfoPlistsourcesresourcescopyFilesheadersentitlementsscriptsdependenciessettingscoreDataModelsenvironmentVariableslaunchArgumentsadditionalFilesbuildRulesmergedBinaryTypemergeableonDemandResourcesTagsmetadatabuildableFoldersforeignBuild
- 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:)
public struct Target: Codable, Equatable, SendableA target of a project.
Properties
name
public var name: StringThe name of the target. Also, the product name if not specified with productName.
destinations
public var destinations: DestinationsThe destinations this target supports, e.g. iPhone, appleVision, macCatalyst
product
public var product: ProductThe type of build product this target will output.
productName
public var productName: String?The built product name. If nil, it will be equal to name.
bundleId
public var bundleId: StringThe product bundle identifier.
deploymentTargets
public var deploymentTargets: DeploymentTargets?The minimum deployment targets your product will support.
infoPlist
public var infoPlist: InfoPlist?The Info.plist representation.
sources
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
public var resources: ResourceFileElements?The resource files of target. Note: localizable files, *.lproj, are supported.
copyFiles
public var copyFiles: [CopyFilesAction]?The build phase copy files actions for the target.
headers
public var headers: Headers?The headers for the target.
entitlements
public var entitlements: Entitlements?The entitlements representation.
Note: For per-configuration entitlements, you should:
- Keep this property as
nil- Set the
CODE_SIGN_ENTITLEMENTSbuild setting usingTarget.settingsfor each configuration- If you want the entitlement files to be included in the project navigator, add them using
Project.additionalFilesExample:
swiftlet 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
public var scripts: [TargetScript]The build phase scripts actions for the target.
dependencies
public var dependencies: [TargetDependency]The target's dependencies.
settings
public var settings: Settings?The target's settings.
coreDataModels
public var coreDataModels: [CoreDataModel]The Core Data models.
environmentVariables
public var environmentVariables: [String: EnvironmentVariable]The environment variables. Used by autogenerated schemes for the target.
launchArguments
public var launchArguments: [LaunchArgument]The launch arguments. Used by autogenerated schemes for the target.
additionalFiles
public var additionalFiles: [FileElement]The additional files for the target. For project's additional files, see Project/additionalFiles.
buildRules
public var buildRules: [BuildRule]The build rules used for transformation of source files during compilation.
mergedBinaryType
public var mergedBinaryType: MergedBinaryTypeSpecifies whether if the target can merge or not the dynamic dependencies as part of its binary
mergeable
public var mergeable: BoolSpecifies whether if the target can be merged as part of another binary or not
onDemandResourcesTags
public var onDemandResourcesTags: OnDemandResourcesTags?The target's tags associated with on demand resources
metadata
public var metadata: TargetMetadataThe target's metadata.
buildableFolders
public var buildableFolders: [BuildableFolder]The target's buildable folders.
foreignBuild
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:)
public static func foreignBuild(
name: String,
destinations: Destinations,
script: String,
inputs: [ForeignBuild.Input] = [],
output: ForeignBuild.Output,
metadata: TargetMetadata = .default
) -> SelfCreates 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)
.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
$SRCROOTset 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 (
.xcframeworkor.framework). - metadata: The target's metadata.
Parameters
| Name | Description |
|---|---|
| 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. |
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:)
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