How to set macOS deployment target on project created with "swift package init --type tool --name MyProject"?

My project created with:

swift package init --type tool --name MyProject
print("\(Date.now)")    // 'now' is only available in macOS 12 or newer

How to set macOS target version to 14.0?

I see: Package.swift has platforms

Added to Package.swift

platforms: [.macOS(.v14)]

When you're using Swift on the command line, it's always (currently) targeting the OS that you're own. Swift only recently started including the capabilities for cross compilation (you can read up the details of the evolution proposal that's been accepted to support this: https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md), which is probably the best documentation on what's to come - but that doesn't help you currently.

In the meantime, if you want to target macOS 14.0 explicitly for a swift package, open the Package.swift in Xcode - it'll allow you to select a specific target and build for that target.

I don't see anyway to set any of this in Xcode. Clicking on the top entry on Project Navigator opens Package.swift

So specifying the platforms arg in Package.swift works.

Sounds good, glad that is working for you!

Nothing wrong with how you pinned it, but worth being aware that platforms stanza in package.swift is specifying the minimum platform that your code should be pinned to (SupportedPlatform | Apple Developer Documentation). in your example, your package wouldn't compile on macOS 12 or 13. If that fits your needs, run with it!

1 Like