Swift Package Manager:依赖iOS版本

11

我正在尝试使用xCode11 beta 7构建swift包并使用外部依赖(CoreStore)。 我的包面向iOS11+,在Package.swift中声明:

// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Storages",
    platforms: [.iOS(.v11)],
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "Storages",
            targets: ["Storages"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(url: "https://github.com/JohnEstropia/CoreStore.git", from: "6.3.0")
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "Storages",
            dependencies: [.product(name: "CoreStore")]),

        .testTarget(
            name: "StoragesTests",
            dependencies: ["Storages"]),
    ]
)

然而,当我构建它时,依赖项将没有指定iOS版本进行构建,因此我会收到兼容性错误:"'uniquenessConstraints' 仅在 iOS 9.0 或更高版本可用"等等。

我该怎么解决呢?看起来像是xCode11的一个bug,但我不确定。

3个回答

9

在我的机器上,将 platforms: 参数添加到清单中解决了这个问题。例如:

let package = Package(
    name: "MyLibrary",
    platforms: [.iOS("13.0")],
    // ...

2
首先,您需要添加一个`platform`参数,并填写支持的平台版本。然后,在主机应用程序中清除派生数据。之后,再次尝试添加spm框架。
我曾经遇到过同样的问题,起初我没有添加平台参数,这导致我的主机应用程序中出现了很多“'xxx'仅在iOS 9.0或更高版本中可用”的错误。希望这能为您解决问题。

2

我不确定这是否是xCode的bug,然而在Swift Package Manager和xCode 11中,当使用#available检查时,你必须明确指定iOS版本。无论库是否针对iOS 10+,都要这样做,而不是

if #available(macOS 10.11, *) {
    info.append(("uniquenessConstraints", self.uniquenessConstraints))
}

你应该使用

if #available(macOS 10.11, iOS 9.0, *) {
    info.append(("uniquenessConstraints", self.uniquenessConstraints))
}

提交了拉取请求: https://github.com/JohnEstropia/CoreStore/pull/341

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接