8

I'm moving my Carthage libraries to Swift Package Manager. If my Swift Package has dependencies to other Swift Packages, do I have to explicitly link those libraries into the project like I do with Carthage, or are the nested dependencies embedded in the Swift Package?

TruMan1
  • 33,665
  • 59
  • 184
  • 335

1 Answers1

0

You can create a target for each dependency (if not exist) and then add them as a dependency. For example, take a look at this:

let package = Package(
    name: "SMUIKit",
    products: [
        .library(
            name: "SMUIKit",
            targets: ["SMUIKit"]),

        .library(
            name: "SMStyleKit",
            targets: ["SMStyleKit"]),
    ],
    dependencies: [
        .package(name: "ExistDependency", url: "https://github.com/mojtabahs/ExistDependency", from: "5.0.0"),
    ],
    targets: [
        .target(
            name: "SMUIKit",
            dependencies: ["SMStyleKit"]
        ),

        .target(
            name: "SMStyleKit",
            dependencies: ["ExistDependency"],
            resources: [.process("Resources")]
        ),
    ]
)

In this package.swift:

  1. SMUIKit and SMStyleKit are libraries that this package creates.
  2. ExistDependency is a package that already exists.
  3. SMUIKit depends on the generated SMStyleKit.
  4. SMStyleKit depends on the SMStyleKit.

I tried to cover some dependency situations but you can R&D more about how you can achieve your needs.

Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278