我用 Xcode 創建了一個新包并合并了一個依賴項,但是當我嘗試使用它時,我得到了一個錯誤。

如何在包源中使用依賴項?在一個普通的專案中,我可以很容易地匯入和使用 AgileDB。
這是包裹:
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "DBCore",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "DBCore",
targets: ["DBCore"]),
],
dependencies: [
.package(url: "https://github.com/AaronBratcher/AgileDB", from: "6.4.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: "DBCore",
dependencies: []),
.testTarget(
name: "DBCoreTests",
dependencies: ["DBCore"]),
]
)
也許 AgileDB 包作為目標中的依賴項?我嘗試復制它,它不會識別它。
uj5u.com熱心網友回復:
找到了我的答案。
在目標依賴項中,需要包含包名作為字串:
// 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: "DBCore",
dependencies: [
"AgileDB"
]),
.testTarget(
name: "DBCoreTests",
dependencies: ["DBCore"]),
]
uj5u.com熱心網友回復:
分步指南:

- 打開專案設定
- 點擊“包依賴”
- 單擊“加號”圖示并在打開的視窗中添加您的包
- 您添加的包應該出現在串列中

- 包也應該出現在左側欄中的“包依賴項”下

- 點擊你的目標
- 導航到“常規”選項卡和該選項下的“框架和庫”部分
- 單擊“加號”圖示并在打開的視窗中選擇/添加您的包
- 您添加的包應該出現在串列中

- 包應自動添加到“Link Binary with Libraries”部分下的“Build Phases”選項卡中。如果未添加,請單擊“加號”圖示
此時,您應該能夠在此目標下的任何檔案中匯入和使用該包。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/465188.html
上一篇:Markdown多行鏈接支持
下一篇:為什么從databrickssparknotebook(hadoopfileUtils)寫入DBFS掛載位置比寫入DBFS根位置慢13倍?
