我想让我已经存在的Cocoapods也可以作为Swift包使用。事情是这样的。我的一个pod依赖于另一个pod,所以我在我的Swift包中添加了以下内容:
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Luminous",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Luminous",
targets: ["Luminous"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(
url: "https://github.com/andrealufino/Deviice.git",
from: "1.30.2"
)
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Luminous",
dependencies: [],
path: "Sources"),
.testTarget(
name: "LuminousTests",
dependencies: ["Luminous"]),
]
)我的另一个问题是:为什么在安装包时会包含Example文件夹?这是这张照片。

此外,最后一件事,当我在我的项目中添加了包时,它失败了,因为它找不到依赖的模块。错误是No such module Deviice。
我想我添加了足够的细节,如果你需要更多,尽管问。
发布于 2020-12-01 16:47:29
我将回答有关找不到Deviice的问题。其他问题是关于本地路径的。
你可以看到你的包是这样的(在下一条评论中,“包”可以理解为库,但也可以理解为可执行文件,用于测试目的通常是“子包”或“真正的可执行文件”。
let package = Package(
name: "Luminous", // Name of your package
products: [], // What packages people will see relying on internal sub-packages
dependencies: [], // External packages you relies on
targets: [] // Internal "sub-packages", etc.
)每个target都有一个dependencies: [],您可以在其中放置其他目标的名称(它是“内部”的,或者是您之前在dependencies[]中声明的公共目标。
.target(
name: "Luminous",
dependencies: [], //Put here names of either sub packages OR public package you "called before"
path: "Sources")在您的案例中:
.target(
name: "Luminous",
dependencies: ["Deviice"],
path: "Sources")确实是你自己写的:
.testTarget(
name: "LuminousTests",
dependencies: ["Luminous"])所以你说它依赖于“发光”子包,这里的逻辑与Deviice相同。
您可以使用Package of Alamofire+Image作为示例。它使用作为外部依赖项的Alamofire,并将其放在原处。
https://stackoverflow.com/questions/65080854
复制相似问题