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?
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.
To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL.
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.
You should write it like this.
.package(url: "https://github.com/onevcat/Hedwig.git", from: "1.0.0"),
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: []
)
]
)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With