简体   繁体   中英

Cannot use Swift Package Manager

I have the latest release versions of Swift and Xcode.

I am trying to use the Swift Package Manager to use this:

.package(url: "https://github.com/matejkosiarcik/Stopwatch.git", from: "0.1.0")

However, I have spent multiple days trying how to figure out how to embed this in my command line tool, or even in a brand new command line tool so that in Main.swift it doesn't give the error:

No such module 'Stopwatch'.

Would someone please explain how to do it for this exact package?

Thank you.

Note that the modules in a Swift Package are specified as targets, not as products.

Suppose you have the following product spec in your Package.swift :

products: [ .library(name: "MyProduct", targets: ["MyTarget1", "MyTarget2"])]

Then in some other package you use this product as a dependency in Package.swift:

.target(name: "TargetInSomeOtherPackage", dependencies: ["MyProduct"])

And in swift code you import modules:

import MyTarget1
import MyTarget2

In your case, you defined your product: .library(name: "Stopwatch", targets: ["lib"]) . This means that you can use Stopwatch as a dependency, and import module lib in your Swift code. There is no module Stopwatch that you can import.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM