需要显式管理 Swift Package 嵌套依赖项吗? [英] Explicitly manage Swift Package nested dependencies required?

查看:39
本文介绍了需要显式管理 Swift Package 嵌套依赖项吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的 Carthage 库移至 Swift Package Manager.如果我的 Swift 包依赖于其他 Swift 包,我是否必须像使用 Carthage 一样将这些库显式链接到项目中,或者嵌套的依赖项是否嵌入到 Swift 包中?

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?

推荐答案

您可以为每个依赖项(如果不存在)创建一个目标,然后将它们添加为依赖项.例如,看看这个:

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")]
        ),
    ]
)

在这个 package.swift 中:

  1. SMUIKitSMStyleKit 是这个包创建的库.
  2. ExistDependency 是一个已经存在的包.
  3. SMUIKit 取决于生成的 SMStyleKit.
  4. SMStyleKit 依赖于 SMStyleKit.
  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.

这篇关于需要显式管理 Swift Package 嵌套依赖项吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆