I have a local swift package Foo which provides two different libraries Foo and FooB. Now I would like to use them in another local package Bar. I am only able to get the whole package by path declaration. Is there a way to name/specify which library should be used? I want to use FooB in my Bar Package.
let package = Package(
name: "Foo",
products: [
.library(name: "Foo", targets: ["Foo"]),
.library(name: "FooB", targets: ["FooB"])
]
...)
let package = Package(
name: "Bar",
dependencies: [
.package(path: "Foo"),
.package(path: "FooB") // this one does not work
],
...)
// inside package Bar
import Foo
import FooB // this is throwing "no such module 'FooB'"
Here's how you can achieve it: specify the target that depends on the specific library from your local Swift package if you want to use it in another package.
☼ For proper local packaging of Foo, it is essential that each library is represented in separate targets. In order to achieve this, amend your Package.swift for Foo in the following manner:
Foo and FooB are the two targets defined, with FooB being dependent on Foo.
☼ Then you can specify the dependency on FooB in your Bar package by rearranging the text.
The Bar target has a dependency on the FooB library, specified by using the product function to point to the package "Foo" and its library "FooB".
☼ Your Bar package can now make use of the FooB library by simply importing it.
Correct import of the FooB library from the Foo package can be accomplished by making specific changes to your Bar package.
According to your project's directory structure and package names, make sure you adjust the paths and package names accordingly. :)