6.1 C
New York
Friday, November 29, 2024

Setting the Swift Language mode for an SPM Bundle – Donny Wals


If you create a brand new Swift Bundle in Xcode 16, the Bundle.swift contents will look a bit like this:

// swift-tools-version: 6.0
// The swift-tools-version declares the minimal model of Swift required to construct this package deal.

import PackageDescription

let package deal = Bundle(
    title: "AppCore",
    merchandise: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "AppCore",
            targets: ["AppCore"]),
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "AppCore"
        ),

    ]
)

Discover how the package deal’s Swift instruments model is ready to six.0. If you need your venture to reference iOS18 for instance, you are going to have to have you ever Swift instruments model set to six.0. A facet impact of that’s that your package deal will now construct within the Swift 6 language mode. Which means that you’ll get Swift’s full suite of sendability and concurrency checks in your package deal, and that the compiler will flag any points as errors.

You won’t be prepared to make use of Swift 6.0 in your new packages but. In these circumstances you possibly can both set the Swift instruments model again to five.10 in case you’re not utilizing any options from the 6.0 toolchain anyway or you possibly can set your package deal’s language mode to Swift 5 whereas conserving the 6.0 toolchain:

// swift-tools-version: 6.0
// The swift-tools-version declares the minimal model of Swift required to construct this package deal.

import PackageDescription

let package deal = Bundle(
    title: "AppCore",
    platforms: [.iOS(.v18)],
    // ... the remainder of the package deal description
    swiftLanguageModes: [.version("5")]
)

By utilizing the Swift 5 language mode you possibly can proceed to jot down your code as normal till you are prepared to begin migrating to Swift 6. For instance, you may need to begin by enabling strict concurrency checks.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles