8

我正在使用 Xcode 12 beta 2。我已将我的库打包在 Swift Packages 中。DataModel出现在错误消息中的是其中之一,我当前的包WeatherView依赖于它。

我可以很好地构建包,但 Swift UI 预览失败
在此处输入图像描述

build aborted due to an internal error: planningFailed("multiple configured targets of \'DataModel\' are being created for iOS Simulator")

----------------------------------------

SchemeBuildError: Failed to build the scheme "WeatherView"

unexpected service error: build aborted due to an internal error: planningFailed("multiple configured targets of \'DataModel\' are being created for iOS Simulator")

Build system information:
error: unexpected service error: build aborted due to an internal error: planningFailed("multiple configured targets of \'DataModel\' are being created for iOS Simulator")
4

2 回答 2

10

我发现使产品库“动态”(而不是静态)使我的预览可以从包的目标内部工作。

let package = Package(
    name: "Modules",
    platforms: [
        .iOS(.v13)
    ],
    products: [
        .library(
            name: "Modules",
            type: .dynamic,
            targets: ["App"]
        ),
    ],
    dependencies: [],
    targets: [
        .target(
            name: "App",
            dependencies: []
        ),
        .testTarget(
            name: "AppTests",
            dependencies: ["App"]
        ),
    ]
)

还必须声明包的平台。

于 2020-10-17T12:45:20.477 回答
3

尝试预览视图的 SwiftUI 画布时,我遇到了同样的错误。我在 Xcode 中打开了多个选项卡。我关闭了所有其他选项卡,但带有我的视图和画布预览的选项卡又开始工作了。

于 2021-03-25T20:52:39.507 回答