3.7 C
Canberra
Wednesday, July 23, 2025

Setting the Swift Language mode for an SPM Package deal – Donny Wals


Once you create a brand new Swift Package deal in Xcode 16, the Package deal.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 bundle.

import PackageDescription

let bundle = Package deal(
    identify: "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 bundle’s Swift instruments model is ready to six.0. If you would like your mission to reference iOS18 for instance, you are going to must have you ever Swift instruments model set to six.0. A facet impact of that’s that your bundle will now construct within the Swift 6 language mode. Which means that you will get Swift’s full suite of sendability and concurrency checks in your bundle, and that the compiler will flag any points as errors.

You may not be prepared to make use of Swift 6.0 in your new packages but. In these instances you may both set the Swift instruments model again to five.10 when you’re not utilizing any options from the 6.0 toolchain anyway or you may set your bundle’s language mode to Swift 5 whereas maintaining the 6.0 toolchain:

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

import PackageDescription

let bundle = Package deal(
    identify: "AppCore",
    platforms: [.iOS(.v18)],
    // ... the remainder of the bundle description
    swiftLanguageModes: [.v5]
)

It is also doable to assign the swift language mode for particular targets in your bundle as an alternative. This is what that appears like:

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",
    swiftSettings: [.swiftLanguageMode(.v5)]
  )
]

Through the use of the Swift 5 language mode you may proceed to put in writing your code as common till you are prepared to start out 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

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles