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)
The Swift Package Manager can be used to add external libraries in Xcode projects. This makes the tool a good alternative to Cocoapods and Carthage for managing the dependencies of an iOS project.
To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL.
With Xcode 13, you need to add packages through the new menu they introduced with the Swift Package Collections. To find this menu, you need to navigate to your project settings where you can find a new menu for Swift Packages. From here you can click the + button to add new packages.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With