Can't import packages using Swift 4 Package Manager
Turns out I had to also include the dependencies into the .target
of the Package.swift:
.target(named: "sampleproject", dependencies: ["Kitura", "Alamofire"])
and build the project again.
Swift - Can't import packages
In your Package.swift
file you are declaring Embassy
as a dependency, but you are not referencing that dependency in any of your targets. In the example you provided, you can alter your package like this:
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "test",
dependencies: [
.package(url: "https://github.com/envoy/Embassy.git", from: "4.1.1"),
],
targets: [
// Reference the 'Embassy' package here.
.target(name: "test", dependencies: ["Embassy"]),
.testTarget(name: "testTests", dependencies: ["test", "Embassy"]),
]
)
Getting 'no such module' error when importing a Swift Package Manager dependency
It turned out that Swift Package Manager implicitly depends on the project's Configuration names. I had them at live/qa instead of Release/Debug, and changing them back resolved the issue. Very odd, but I hope it saves you some trouble dear reader.
Unable to import Swift package that contains only Objc Code
Tweaking the package.swift file fixed it
.target(
name: "MyLibrary",
dependencies: [],
publicHeadersPath: "Public")
add a folder called Public
inside the source folder and move all the public headers there. Now the package is visible in the project
I can't import my swift package into a project
Your package does not pass the build due to availability errors:
You need to specify the minimum deployment target for the iOS platform. (which I suppose you are interested in)
Since you are using API that is only available in iOS 14 or newer, you can add the platforms
parameter to Package
initializer in your manifest file like so:
let package = Package(
name: "UnsplashSwiftUI",
platforms: [.iOS(.v14)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "UnsplashSwiftUI",
targets: ["UnsplashSwiftUI"]),
],
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 this package depends on.
.target(
name: "UnsplashSwiftUI",
dependencies: []),
]
)
That fixed your issue.
How to use other swift packages in an own swift package?
As previous mentioned, you have to set the dependencies "Alamofire" and "Sodium" to the target. For example:
.target(
name: "SpaceCryptography",
dependencies: ["Alamofire", "Sodium"]),
I recommend to also give names to the dependencies packages defined above:
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(name: "Sodium", url: "https://github.com/jedisct1/swift-sodium.git", .upToNextMajor(from: "0.9.1")),
.package(name: "Alamofire" url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.5.0"))
]
Importing modules with Swift package manager
Probably the problem lies within Xcode, as it does not know yet that JSON
exists, because it was not built yet. This can easily be solved by just building your project (with cmd-B
). With the generated xcodeproj, Xcode should know that it first needs to build JSON
and then the rest, because JSON
is marked as a dependency for your target.
You can check this, by navigating in Xcode to your target (when you click on the project description file) and afterwards to "Build Phases". Under Target Dependencies you should find your JSON
module.
In addition you should find a JSON
module under your targets, which compiles the sources you gathered from github.
Your project should also build when executing swift build
in your project root.
Related Topics
How to Compare Two Strings to Check If They Have Same Characters Swift 4
How to Get All Text from a PDF in Swift
Custom Cell with Uitableview Inside Uicollectionviewcell
Simple Swift Class Does Not Compile
Passing Unknown Number of Arguments in a Function
Randomize Two Arrays the Same Way Swift
Tests for Custom Uitableviewcell, Cellforrowatindexpath Crashes with Nil Outlets
Equivalent of Skaction Scaletox for a Given Duration in Unity
Why Do We Need to Specify Init Method
Swift Switch Char{ Case "\U{E2}:
Get Images from Document Directory Not File Path Swift 3
Initializer for Conditional Binding Must Have Optional Type, Not '[String:Any]'
How to Pass Closure as a Parameter in Perform(Selector, Withobject)
Core Data Update in Swift While Selecting Any Row in List Table View Not Working
Retrieve an Image from Firebase to an Uiimage Swift5
Get All Documents at Once in a Completion Handler with Getdocuments in Firestore