Package

    The configuration of a Swift package.

    PackageDescription.swift:79Package.md
    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, you need to define the properties of a package in a single nested initializer statement. Don’t modify it after initialization. The following package manifest shows the initialization of a simple package object for the MyLibrary Swift package:

    // swift-tools-version:5.3
    import PackageDescription
    
    let package = Package(
        name: "MyLibrary",
        platforms: [
            .macOS(.v10_15),
        ],
        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"])
        ]
    )

    In Swift tools versions earlier than 5.4, the package manifest must begin with the string // swift-tools-version: followed by a version number specifier. Version 5.4 and later has relaxed the whitespace requirements. 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.3
    // swift-tools-version: 5.6

    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 required minimum version of the Swift tools to use the Swift package. Each version of Swift can introduce updates to the PackageDescription framework, but the previous API version is available to packages which declare a prior tools version. This behavior means you can 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.

    Creating a Package

    Naming the Package

    Localizing Package Resources

    Configuring Products

    Configuring Targets

    Declaring Supported Platforms

    Configuring System Packages

    Declaring Package Dependencies

    Declaring Supported Languages

    See also

    Citizens in PackageDescription

    Type members

    Show obsolete interfaces (3)

    Hide obsolete interfaces