Package.Dependency没有成员包

时间:2018-03-27 01:18:14

标签: ios swift

我正在处理我的应用,并且在添加包时我不断收到此错误,因此我可以将其导入。

error: type 'Package.Dependency' has no member 'Package'

这是我的Package.swift代码:

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

import PackageDescription

let package = Package(
    name: "xHelp",
    dependencies: [
        .Package(url: "https://github.com/onevcat/Hedwig.git",
                 majorVersion: 1)
    ],
    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: "xHelp",
            dependencies: ["Hedwig"]),
        .testTarget(
            name: "xHelpTests",
            dependencies: ["xHelp"]),
        ]
)

我已尝试this SO帖子,但它没有用。我该怎么办?

3 个答案:

答案 0 :(得分:6)

你应该这样写。

.package(url: "https://github.com/onevcat/Hedwig.git", from: "1.0.0"),

答案 1 :(得分:1)

就我而言,我遇到类似type 'Target.Dependency' has no member 'package'的错误。问题是,我将包声明放置在Target依赖项中,而不是顶层Package依赖项中。

错误的Package.swift:

let package = Package(
    name: "PackageName",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.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: "PackageName",
            dependencies: [.package(
                    url: "https://github.com/jpsim/Yams.git",
                    from: "1.0.1")]
        )
    ] 
)

已修复

let package = Package(
    name: "PackageName",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(
            url: "https://github.com/jpsim/Yams.git",
            from: "1.0.1")
    ],
    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: "PackageName",
            dependencies: []
        )
    ]
)

答案 2 :(得分:1)

一切正常,只能将大写字母P更改为p

.Package(url:“ https://github.com/onevcat/Hedwig.git”, majorVersion:1)

小写

.package(url:“ https://github.com/onevcat/Hedwig.git”, majorVersion:1)