一、使用swift package init
- cd到项目目录下
- 执行swift package 操作
swift package init --type library
文件输出:
生成 Swift Package Manger 所需要的目录和相关文件。
二、修改 Package.swift 及文件目录
我们可以看到命令为我们生成了 Sources 和 Tests 的目录,及其一些配置文件。但是我原本项目的代码并不是放在该目录下的,而且我也没有配置测试的 Target,所以直接把 Sources 和 Tests 都删掉,在 Package.swift 中去指定我的代码路径。
这是我修改后的 Package.swift :
import PackageDescription
let package = Package(
name: "BaseAlgorithm",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "BaseAlgorithm",
targets: ["BaseAlgorithm"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
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: "BaseAlgorithm",
dependencies: [],
path: "BaseAlgorithm")
],
swiftLanguageVersions: [.v5]
)
注意:在
.target
里添加了path,这里就是我的源码路径