Why add `platforms: [.macOS(.v12)]`?

Now that Swift includes concurrency, why is it necessary to add

platforms: [.macOS(.v12)],

to a Package.swift file in order to use it? This seems very odd to me - especially when compiling on Linux.

1 Like

You don't need to add that, but you need to add availability annotations otherwise. This is because all Swift packages are considered cross-platform.

1 Like

So could I just add something like platforms: [.linux], if the app is intended to only run on linux?

Unfortunately SPM doesn't support setting the platforms your package supports, only its deployment targets, which are then used in the @availability checks. I suggest you set the Apple platform deployment targets to their latest versions and don't worry about it.

Thanks for the explanations, which I gratefully accept. I had assumed platform and deployment target to be one of the same.

Google says, "Semantics is the branch of linguistics and logic concerned with meaning. The two main areas are logical semantics , concerned with matters such as sense and reference and presupposition and implication, and lexical semantics , concerned with the analysis of word meanings and relations between them."

Then you should be able to leave platforms out completely. Is that not the case?

As @lukasa and @Jon_Shier have explained, you can or you can't - depending on how much extra code you're prepared to write.

Their comments are both true of a package that actually supports macOS, but are not relevant to a package that does not support macOS in the first place. It seems to me they answered a different question than was asked.

When building for Linux, neither platforms: [.macOS(.v12)] nor @available(macOS 12, *) should have any effect. If you really have encountered some sort of error or warning telling you to add them—which is how I read your question—, then there is a bug we need to fix.


Darwin and Linux are similar, so I wouldn't describe it as a bug. It's just that Apple is stuck in an IOS world. Take SwiftUI - great for small screens, but very slow and often unusable on the desktop - simply because it swamps the main thread. This doesn't speed up interactivity, it slows it down.

I'm devoted to Apple, but there's a big but to my loyalty. They seem to have lost the lateral thinkers they once had. Perhaps if they began manufacturing SBCs for the education and industrial sectors, things would improve. I persevere in hope.