最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Default swift build to modern platforms? - Stack Overflow

programmeradmin0浏览0评论

I'm really not enjoying having to put @available(macOS 12, *) all over the place. Is there a way to configure Swift to just build the code with the assumption that it will work?

For example, in the screenshot below, I have already added the annotation twice, but it seems to require a third annotation just to satisfy the LSP (and then presumably the compiler).

I really don't care if whatever it's complaining about was first available in macOS versions I don't intend to target. I just want the code to compile for the latest OS.

I'm really not enjoying having to put @available(macOS 12, *) all over the place. Is there a way to configure Swift to just build the code with the assumption that it will work?

For example, in the screenshot below, I have already added the annotation twice, but it seems to require a third annotation just to satisfy the LSP (and then presumably the compiler).

I really don't care if whatever it's complaining about was first available in macOS versions I don't intend to target. I just want the code to compile for the latest OS.

Share Improve this question edited Feb 2 at 12:31 James Sumners asked Feb 1 at 16:11 James SumnersJames Sumners 14.8k11 gold badges61 silver badges77 bronze badges 1
  • There is no reason this question should be closed. The question is right in the title, and the body provides the details. The person, it seems, that has closed this has assumed something not even mentioned. I very specifically asked about "swift build" and the LSP. – James Sumners Commented Feb 2 at 12:29
Add a comment  | 

1 Answer 1

Reset to default 0

To solve this, add a platforms block to the Package.swift file. So, if the Package.swift file is:

// swift-tools-version:6.0

import PackageDescription

let package = Package(
    name: "Example",

    products: [
        .library(name: "Example", targets: ["Example"])
    ],

    targets: [
        .target(name: "Example", dependencies: []),
        .testTarget(name: "ExampleTests", dependencies: ["Example"]),
    ]
)

Update it to:

// swift-tools-version:6.0

import PackageDescription

let package = Package(
    name: "Example",

    // This definition let's us skip adding `@available(macOS 12, *)`
    // throughout the project.
    platforms: [
        .macOS(.v12)
    ],

    products: [
        .library(name: "Example", targets: ["Example"])
    ],

    targets: [
        .target(name: "Example", dependencies: []),
        .testTarget(name: "ExampleTests", dependencies: ["Example"]),
    ]
)
发布评论

评论列表(0)

  1. 暂无评论