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
1 Answer
Reset to default 0To 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"]),
]
)