![](/img/trans.png)
[英]How to import a package's dependency when using Swift Package Manager?
[英]How to add dependency using Swift package manager
我正在使用 xcode 版本 10.1 和 swift 4 我想添加一个新的依赖项 https://github.com/theIBM-Swift/BlueECC/b使用以下现有项目安装到 mymaster/theREADME 步骤。 swift package 经理
但是 package 没有被导入,请纠正我的错误
有四种方法可以在 Package.swift 清单文件中添加依赖项。 添加 Alamofire 库作为示例。
使用标签版本
// Syntax
.package(url: "Repository URL", from: "Version")
// Example
.package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.0.2")
使用分支名称
// Syntax
.package(url: "Repository URL", .branch("branch-name"))
// Example
.package(url: "https://github.com/Alamofire/Alamofire.git", .branch("master"))
使用提交 ID
// Syntax
.package(url: "Repository URL",
.revision("commit-id"))
// Example
.package(url: "https://github.com/Alamofire/Alamofire.git",
.revision("eb67560abbc58e7d98e6e17daa5bd9376625f038"))
使用本地存储库
// Syntax
.package(path: "../Repository local path")
// Example
.package(path: "../Alamofire")
After that add this to your target section in Package.swift file: This is mandatory to add as this will make the module accessible to Swift PM, otherwise library/module will not accessible in Swift PM.
// Syntax
.target(
name: "target-name",
dependencies: ["dependency-name"]),
// Example
.target(
name: "MyApp",
dependencies: ["Alamofire"]),
请在此处找到有关 Swift PM 的更多技术细节。
您将需要 package URL、版本号和 package 的名称。
将此添加到您的清单中:
.package(url: 'the url of the package', from: 'version number')
之后将其添加到您的目标文件中:
.target(
name: "target-name",
dependencies: ["dependency-name"]),
To add any third party swift package as a dependency in your swift package first you have to add the package url and requirements to the package dependency:
.package(url: "https://github.com/IBM- Swift/BlueECC.git", from: "1.2.4")
在上面的片段中,我提供了一个版本要求的示例,您还可以有分支和提交要求。
接下来,要使用来自 3rd 方依赖项的模块,您必须在目标依赖项中指定包含该模块的产品名称和 package 名称:
.product(name: "CryptorECC", package: "BlueECC")
您可以在 3rd 方库的 package 清单的产品部分中查看哪些产品包含哪些模块:
products: [ // Products define the executables and libraries produced by a package, // and make them visible to other packages. .library( // the product name name: "CryptorECC", // included modules in product targets: ["CryptorECC"] ) ],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.