Reputation: 19662
In order to have some code compile with SwiftPM, without adding #if available
, I'm building the project with the following parameters:
swift build -Xswiftc "-target" -Xswiftc "x86_64-apple-macosx10.11"
Swift Package Manager also works with Xcode .xcconfig
files, but only when generating an Xcode project.
Is there an easy way in Swift 5 to specify the minimum version of macOS when building from the command line with swift build
?
Compiler error example:
error: 'archivedData(withRootObject:)' is only available on OS X 10.11 or newer
let data = NSKeyedArchiver.archivedData(withRootObject: value)
Upvotes: 34
Views: 18516
Reputation: 81
Alex 's answer is useful
But when i try to run an old project, still error. The file header needs to be modified to
// swift-tools-version:5.0
'platforms' is affective after 5.0
Upvotes: 2
Reputation: 1565
let package = Package(
name: "NAME",
platforms: [
.macOS(.v10_11)
],
products: [
.library(name: "NAME", targets: ["NAME"]),
],
targets: [
.target(name: "NAME"),
]
)
One way to do this is with Deployment Settings in SPM.
Upvotes: 65