问题描述
我正在将我的 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
中:
SMUIKit
和SMStyleKit
是这个包创建的库.ExistDependency
是一个已经存在的包.SMUIKit
取决于生成的SMStyleKit
.SMStyleKit
依赖于SMStyleKit
.
SMUIKit
andSMStyleKit
are libraries that this package creates.ExistDependency
is a package that already exists.SMUIKit
depends on the generatedSMStyleKit
.SMStyleKit
depends on theSMStyleKit
.
我试图涵盖一些依赖情况,但您可以研发更多关于如何满足您的需求.
I tried to cover some dependency situations but you can R&D more about how you can achieve your needs.
这篇关于需要显式管理 Swift Package 嵌套依赖项吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!