I would like to create a Swift library package just for iOS, and not for Mac. Therefore, i have a package file as follows:
let package = Package(
name: "Example",
platforms: [
.iOS(.v11)],
products: [
.library(
name: "Example",
targets: ["Example"]
)
],
targets: [
.target(name: "Example",
path: "Example/Example")
]
)
As you can see, I do not include Mac in the platforms. However, when I try to build from the package, it fails with:
ReplayKit is not available when building for macOS. Consider using `#if !os(macOS)` to conditionally import this framework.
And same for any type not available for Mac. How can I solve that?
The platforms
section of the package is the minimum deployment targets of the specified platforms not a list of platforms the package supports. So if you don't specify .macOS(...)
then you get the default which is believe is .v10_10
.
Unfortunately that means you have to determine what is available and put int inside of #if !os(macOS)
blocks like the build error says.