The configuration of a Swift package.


final class Package


Pass configuration options as parameters to your package’s initializer statement to provide the name of the package, its targets, products, dependencies, and other configuration options.

By convention, the properties of a Package are defined in a single nested initializer statement, and not modified after initialization. The following package manifest shows the initialization of a simple package object for the MyLibrary Swift package:

// swift-tools-version:5.1
import PackageDescription

let package = Package(
    name: "MyLibrary",
    platforms: [
    products: [
        .library(name: "MyLibrary", targets: ["MyLibrary"]),
    dependencies: [
        .package(url: "https://url/of/another/package/named/Utility", from: "1.0.0"),
    targets: [
        .target(name: "MyLibrary", dependencies: ["Utility"]),
        .testTarget(name: "MyLibraryTests", dependencies: ["MyLibrary"]),

A Package.swift manifest file must begin with the string // swift-tools-version: followed by a version number specifier. The following code listing shows a few examples of valid declarations of the Swift tools version:

// swift-tools-version:3.0.2
// swift-tools-version:3.1
// swift-tools-version:4.0
// swift-tools-version:5.0
// swift-tools-version:5.1

The Swift tools version declares the version of the PackageDescription library, the minimum version of the Swift tools and Swift language compatibility version to process the manifest, and the minimum version of the Swift tools that are needed to use the Swift package. Each version of Swift can introduce updates to the PackageDescription framework, but the previous API version will continue to be available to packages which declare a prior tools version. This behavior lets you take advantage of new releases of Swift, the Swift tools, and the PackageDescription library, without having to update your package’s manifest or losing access to existing packages.


Naming the Package

var name: String

The name of the Swift package.

Configuring Products

var products: [Product]

The list of products that this package vends and that can be run or used by its clients.

class Product

The object that defines a package product.

Configuring Targets

var targets: [Target]

The list of targets.

class Target

A target, the basic building block of a Swift package.

Declaring Supported Platforms

struct SupportedPlatform

A platform that the Swift package supports.

struct Platform

A platform that usually corresponds to an operating system such as iOS, macOS, or Linux.

Configuring System Packages

enum SystemPackageProvider

The system package providers used in this Swift package.

var pkgConfig: String?

The name to use for C Modules.

var providers: [SystemPackageProvider]?

An array of providers for the system target.

Declaring Package Dependencies

var dependencies: [Package.Dependency]

The list of package dependencies.

class Package.Dependency

A package dependency of a Swift package.

Declaring Supported Languages

enum SwiftVersion

The version of the Swift language to use for compiling Swift sources in the package.

enum CLanguageStandard

The supported C language standard to use for compiling C sources in the package.

enum CXXLanguageStandard

The supported C++ language standards to use for compiling C++ sources in the package.

var swiftLanguageVersions: [SwiftVersion]?

The list of Swift versions that this package is compatible with.

var cLanguageStandard: CLanguageStandard?

The C language standard to use for all C targets in this package.

var cxxLanguageStandard: CXXLanguageStandard?

The C++ language standard to use for all C++ targets in this package.

Encoding and Decoding

func encode(to: Encoder)

Encodes this value into the given encoder.


Conforms To

See Also

Local and Standalone Packages

Creating a Standalone Swift Package with Xcode

Bundle executable or shareable code into a standalone Swift package.

Organizing Your Code with Local Packages

Simplify maintenance, promote modularity, and encourage reuse by organizing your app’s code into local Swift packages.

Editing a Package Dependency as a Local Package

Override a package dependency and edit its content by adding a Swift package as a local package.

Developing a Swift Package in Tandem with an App

Add your published Swift package as a local package to your app’s project and develop the package and the app in tandem.