Xcode 为 Mac 编译,即使它不在 Swift.package 的平台字段中
Xcode compiles for Mac even if it is not in the platforms field in the Swift.package
我想为 iOS 而不是 Mac 创建一个 Swift 库包。因此,我有一个包文件如下:
let package = Package(
name: "Example",
platforms: [
.iOS(.v11)],
products: [
.library(
name: "Example",
targets: ["Example"]
)
],
targets: [
.target(name: "Example",
path: "Example/Example")
]
)
如您所见,我没有在平台中包含 Mac。但是,当我尝试从包构建时,它失败了:
ReplayKit is not available when building for macOS. Consider using `#if !os(macOS)` to conditionally import this framework.
对于 Mac 不可用的任何类型也是如此。我该如何解决?
包的 platforms
部分是指定平台的最小部署目标,而不是包支持的平台列表。因此,如果您不指定 .macOS(...)
那么您将获得默认值,即 .v10_10
.
不幸的是,这意味着您必须确定可用的内容并将 int 放入 #if !os(macOS)
块中,就像构建错误所说的那样。
我想为 iOS 而不是 Mac 创建一个 Swift 库包。因此,我有一个包文件如下:
let package = Package(
name: "Example",
platforms: [
.iOS(.v11)],
products: [
.library(
name: "Example",
targets: ["Example"]
)
],
targets: [
.target(name: "Example",
path: "Example/Example")
]
)
如您所见,我没有在平台中包含 Mac。但是,当我尝试从包构建时,它失败了:
ReplayKit is not available when building for macOS. Consider using `#if !os(macOS)` to conditionally import this framework.
对于 Mac 不可用的任何类型也是如此。我该如何解决?
包的 platforms
部分是指定平台的最小部署目标,而不是包支持的平台列表。因此,如果您不指定 .macOS(...)
那么您将获得默认值,即 .v10_10
.
不幸的是,这意味着您必须确定可用的内容并将 int 放入 #if !os(macOS)
块中,就像构建错误所说的那样。