使用Swift 5.1将另一个软件包作为SPM中的依赖项导入到另一个软件包中

时间:2019-11-15 21:36:20

标签: swift swift-package-manager spm

因此,我使用SPM(快速包管理器)来创建自己的包库。我想将另一个包导入到我的包中以供使用,如下所示:

// 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: "SwiftRecommendations",
    platforms: [
        .iOS(.v13),
        .macOS(.v10_13),
        .tvOS(.v13)
    ],
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "SwiftRecommendations",
            targets: ["SwiftRecommendations"]),
    ],
    dependencies: [
        .package(
            url: "https://github.com/apple/swift-log.git",
            .branch("master")
        )
    ],
    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: "SwiftRecommendations",
            dependencies: ["Logging"]),
        .testTarget(
            name: "SwiftRecommendationsTests",
            dependencies: ["SwiftRecommendations", "Logging"]),
    ]
)

我正在尝试在我的测试文件中导入并运行Logger,但是它抱怨在添加导入语句后没有这样的Logger模块。我可以在Xcode中看到Swift包依赖项显示swift-log,所以不确定发生了什么。

我的测试课如下:

import XCTest
import Logger
@testable import SwiftRecommendations

final class SwiftRecommendationsTests: XCTestCase {

    static var tokenService: TokenService?
    var logger: Logger?


    override func setUp(){
        super.setUp()
        self.logger = Logger(label: "com.samba.tv.recommendations")


    }

1 个答案:

答案 0 :(得分:0)

哦,天哪,我确实输入了错误的导入语句。真的很抱歉... :(应该是import Logging而不是import Logger