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?

Terima kasih.

1
RufusV 14 November 2017, 19:22

1 menjawab

Jawaban Terbaik

Perhatikan bahwa modul dalam Paket Swift ditetapkan sebagai target, bukan sebagai produk.

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.

0
Vadim Eisenberg 15 November 2017, 11:14