I'm working on a Swift library that I eventually want to make open source. While working on the library, I am also building an app that is going to use said library, and I keep having problems where files added to the library don't seem to get built and so I keep getting compiler errors.
My workflow so far is as follows:
I created the library with swift package init --type library
. I added the first file, it compiles fine.
I then created the app that is going to use the library with swift package init --type executable
(it's a command line app, not an iOS app).
In the command line app's Package.swift I am using the library as a dependency:
import PackageDescription
let package = Package(
name: "CLI",
dependencies: [
.package(path: "../Library"),
],
targets: [
.target(
name: "CLI",
dependencies: ["Library"]),
.testTarget(
name: "CLI Tests",
dependencies: ["CLI"]),
]
)
- I open the CLI project in Xcode, I can expand the Library and work on the one existing file I added earlier, and everything works, everything compiles. But as soon as I add a new file to the Library and try to use it in the CLI to even within the Library itself, I keep getting compiler errors that it can't find the struct/class/func/whatever I added in that new file. Eventually the error fixes itself, but I have no idea how or why, it seems random.
For example, see this screenshot:
It says it can't find PublishingError
even though I did add that (you can see it in the filelist, and yes it contains a struct called PublishingError
). Why can't it find this?
What is the correct workflow to work with a local dependency you're building, so that files compile as expected?
question from:
https://stackoverflow.com/questions/65876139/correct-workflow-for-working-on-a-local-swiftpm-library 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…