我一直在嘗試將我制作的現有 swift 包重構為多個 swift 包。
我首先將代碼從原始包(“Parent”)移動到第二個包(“Child”)中,它們位于同一個 xcworkspace 中。在公開我需要的代碼并import Child在呼叫來自 Child 的那些方法簽名的檔案上使用之后,主要目標構建。
當我嘗試運行測驗時會出現問題。Child 包中的測驗運行良好,但是當 Parent 的測驗嘗試構建時,它無法與這些錯誤鏈接......
未定義符號:Child.SomeProtocol 的協議描述符
未定義符號:(Child 中的擴展):Child.SomeProtocol.method(param: CoreGraphics.CGFloat) -> CoreGraphics.CGFloat
未定義符號:靜態(子級擴展):Swift.Double.computedProperty.getter:Swift.Double
...另一個指標指向匯入陳述句。
我做的第一件事是將子目標添加到父構建方案中,并選中“測驗”和“運行”。然后我嘗試通過將子項添加到測驗目標的依賴項來調整父項的包檔案...
targets: [
.target(
name: "Parent",
dependencies: [],
resources: [.process("Resources")]),
.testTarget(
name: "ParentTests",
dependencies: ["Parent"/*, "Child"*/]), // <-- Part inside /* comments */ is what I added
]
然后我的錯誤變為......
未找到包“Parent”目標“ParentTests”所需的產品“Child”。
盡管該專案的行為就像它已成功構建,但當我嘗試運行測驗并得到一個彈出視窗時,我只看到錯誤:
沒有可用于測驗的測驗包。
確保所有包依賴關系都已解決,并且活動方案或測驗計劃中沒有丟失的測驗包。
我在 github 上找到了托管包的說明,但這帶來了一系列其他問題。為簡單起見,如何正確地將子包鏈接到父包作為我作業區中的本地依賴項?
另外,我注意到問題不僅在于測驗,而且當我嘗試構建擁有 Parent 包的主機應用程式時,我會遇到類似的錯誤。
以下是我的 Parent ("Trenches_Engine") 和 Child ("Math") 包的實際包...
// swift-tools-version:5.5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Trenches_Engine",
platforms: [
.iOS(.v14)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Trenches_Engine",
targets: ["Trenches_Engine"]),
],
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: "Trenches_Engine",
dependencies: [],
resources: [.process("Resources")]),
.testTarget(
name: "Trenches_EngineTests",
dependencies: ["Trenches_Engine", "Math"]),
]
)
// swift-tools-version: 5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Math",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Math",
targets: ["Math"]),
],
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: "Math",
dependencies: []),
.testTarget(
name: "MathTests",
dependencies: ["Math"]),
]
)
這是無法識別的協議/擴展(并且是當前包中唯一的一個)...
import CoreGraphics
/// This protocol provides `random` and `random:min:max` methods that return CGFloat.
public protocol CanRandom { }
// TODO: Replace this with new random methods...
public extension CanRandom {
/// This method returns a random CGFloat without any setup parameters.
///
/// - Returns: CGFloat(Float(arc4random()) / 0xFFFFFFFF)
func random() -> CGFloat { CGFloat(Float(arc4random()) / 0xFFFFFFFF) }
/// This method returns a random CGFloat, within the range defined by parameters.
///
/// - Parameter min: The floor of acceptable range of random numbers.
/// - Parameter max: The ceiling of acceptable range of random numbers.
///
/// - Returns: random() * (max - min) min
func random(min: CGFloat, max: CGFloat) -> CGFloat {
random() * (max - min) min
}
}
uj5u.com熱心網友回復:
它需要在包的依賴項中使用不同的包方法...
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(name: "Child", path: "../Child")
]
連同“目標”陣列中的這個:
.target(
name: "Parent",
dependencies: [.product(name: "Child", package: "Child")],
resources: [.process("Resources")]),
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/520988.html
上一篇:在這種情況下,如何使用Jest監視第二個函式object.functionOne().functionTwo()
