Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package.Dependency has no member Package

Tags:

ios

swift

I am working on my app, and I keep getting this error when I add a package so I can import it.

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

This is my Package.swift code:

// 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"]),
        ]
)

I have tried this SO post, but it didn't work. What should I do here?

like image 675
jackmerrill Avatar asked Mar 27 '18 01:03

jackmerrill


People also ask

What is package dependency?

A dependency is another package that your package needs in order to work. Dependencies are specified in your pubspec. You list only immediate dependencies—the software that your package uses directly.

How do I add a Swift package dependencies in Xcode 13?

To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL.

How do I install a Swift package?

The easiest option to add a Swift package is by entering the package URL in the search field in the top right. The package URL is the location where the Swift Package Manager can find the Package. swift file of the package, that is, the manifest of the package. For RxSwift, that simply means adding the GitHub URL.


3 Answers

You should write it like this.

.package(url: "https://github.com/onevcat/Hedwig.git", from: "1.0.0"),
like image 173
David Avatar answered Nov 15 '22 09:11

David


In my case, I was getting an error like: type 'Target.Dependency' has no member 'package'. The issue was, I was putting the package declaration within the Target dependency, rather than the top level Package dependency.

Wrong 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")]
        )
    ] 
)

FIXED:

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: []
        )
    ]
)
like image 26
rounak Avatar answered Nov 15 '22 08:11

rounak


Everything its okay only change capital P to p in

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

to lowercase

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

like image 29
Mashal Avatar answered Nov 15 '22 08:11

Mashal