Swift 程序包管理器 - 未加载语音依赖项

Swift Package Manager - Speech dependency not loading

我在为我的项目创建 Swift 包时遇到问题。我有 CocoaPods 和 Travis CI 运行ning,两者都在顺畅地工作,但我现在还打算通过 Swift 包管理器提供该项目。这就是我 运行 遇到问题的地方。我的包文件如下所示:

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

import PackageDescription

let package = Package(
    name: "Voxosonus",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "Voxosonus",
            targets: ["Voxosonus"]),
    ],
    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: "Voxosonus",
            path: "Voxosonus"),
        .testTarget(
            name: "VoxosonusTests",
            dependencies: ["Voxosonus"],
            path: "VoxosonusTests"),
    ]
)

但是当我 运行 swift build 我遇到以下情况:

/Users/<hidden>/Documents/Projecten/Voxosonus/Voxosonus/SpeechRecognizer.swift:8:8: error: no such module 'Speech'
import Speech

我的问题是 - 为什么找不到 'Speech' 模块?这是 Apple 自己的核心功能,到目前为止,互联网让我 none 变得更聪明了。项目的一些细节:

构建目标:iOS 12.x

macOS:10.14

Swift版本:4.2.1

Swift Package Manager Github 中所述,您还不能定义 Swift 包 的目标平台:

At this time there is no explicit support for depending on UIKit, AppKit, etc, though importing these modules should work if they are present in the proper system location. We will add explicit support for system dependencies in the future. Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.

因此,当您尝试使用 Xcode(或使用 swift build 命令)构建库时,编译器找不到 语音模块,因为它只在iOS 10+上可用。

你可以检查这个 github project (swift-package-manager-ios) 它提供了一个 ruby 脚本来修改 xcodeproj 生成的Swift Package Manager 添加必要的信息以便为 iOS 平台构建。