Swift Package Manager:依赖项iOS版本

时间:2019-09-03 15:34:43

标签: swift xcode11 swift-package-manager corestore

我正在尝试使用xCode11 beta 7构建具有外部依赖性(CoreStore)的swift程序包。我的程序包适用于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' is only available in iOS 9.0 or newer",依此类推。

我该如何解决?看起来是xCode11错误,但我不确定。

3 个答案:

答案 0 :(得分:0)

我不确定是否是xCode错误,但是使用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

答案 1 :(得分:0)

首先,您需要添加一个function findSequential(str) { const res = []; let currentHigh = 0; for (let char of str) { if (+char === currentHigh + 1) { currentHigh++; } else if (currentHigh > 0) { res.push(buildSequence(currentHigh)) currentHigh = +char === 1 ? 1 : 0; } } if (currentHigh > 0) { res.push(buildSequence(currentHigh)); } return res; } function buildSequence(max) { if (max <= 1) { return "1"; } else { return buildSequence(max - 1) + max; } } console.log(findSequential("456000123456009123456780001234000")); // ["123456", "12345678", "1234"] console.log(findSequential("12")); // ["12"] console.log(findSequential("1212")); // ["12", "12"] console.log(findSequential("23")); // []参数,并使用支持的平台版本对其进行填写。然后,您需要在主机应用中platform。之后,尝试再次添加spm框架。

我也有同样的事情,起初我没有添加platform参数,这给了我太多的“'xxx'仅在iOS 9.0或更高版本的主机应用程序中可用”错误。希望能为您修复它。

答案 2 :(得分:0)

在我的机器上,将platforms:参数添加到清单可以解决该问题。例如:

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