Swift 包管理器 - 分发一个已经存在的 Cocoapod
Swift Package Manager - Distribute an already existing Cocoapod
我想让我现有的 Cocoapods 也可以作为 Swift 包使用。
事情是这样的。我的 pods 中的一个依赖于另一个,所以我将其添加到我的 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
.
我想我已经添加了足够的细节,如果你需要更多,尽管问。
我会回答 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: []
,这是您放置其他目标(“内部”或 public 名称的地方,您之前在 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"])
所以你说它依赖于子包“Luminous”,这里的逻辑与Deviice
相同。
您可以使用 Package of Alamofire+Image 作为示例。它用作外部依赖项 Alamofire
,并按原样放置。
我想让我现有的 Cocoapods 也可以作为 Swift 包使用。 事情是这样的。我的 pods 中的一个依赖于另一个,所以我将其添加到我的 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
.
我想我已经添加了足够的细节,如果你需要更多,尽管问。
我会回答 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: []
,这是您放置其他目标(“内部”或 public 名称的地方,您之前在 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"])
所以你说它依赖于子包“Luminous”,这里的逻辑与Deviice
相同。
您可以使用 Package of Alamofire+Image 作为示例。它用作外部依赖项 Alamofire
,并按原样放置。