SwiftUI 预览显示错误 - 无法在此文件中预览 - 当前目标需要调整build设置

标签 swiftui xcode11 xcode11.1

我使用的是 Xcode 11.1,我所有的 swift 预览都显示以下错误:

swiftui preview pane error

Cannot preview in this file -- current target needs adjusted build settings

连同

"ProjectTests.xctest' failed to get build settings: unsupportedProductType("com.apple.product-type.bundle.unit-test", <Xc..."

单击诊断按钮会生成以下弹出窗口:

enter image description here

Open file has supported build settings "ProjectTests.xctest" failed to get build settings: unsupportedProductType("com.apple.product-type.bundle.unit-test", <Xcode3TargetProduct:0xblahblahblahProjectTests.xctest blueprint:< Xcode3Target:0xblahblahProjectTests>>)

我的预览仍然可以正常渲染,但是有什么方法可以消除这个错误吗?

最佳答案

将目标更改为某个模拟器而不是“iOS 通用设备”或在预览提供程序中明确指定预览设备,例如

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
        .previewDevice("iPhone 11")
    }
}

Xcode 版本 11.1 (11A1027)

关于SwiftUI 预览显示错误 - 无法在此文件中预览 - 当前目标需要调整build设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58653365/

相关文章:

SwiftUI 条件列表 - 无法推断复杂的闭包返回类型

ios - SwiftUI如何设置下划线与文字的间距?

swift - 在 SwiftUI 中获取当前纬度和经度

ios - 如何在 SwiftUI 中访问 'sender' 进行手势?

ios - 找不到目标 'MyCustomFramework' 的模块 'x86_64-apple-ios-simulator' ;找到 : arm64, armv7-apple-ios,arm64-apple-ios,arm,armv7

xcode11 - Xcode 11 beta 模拟器在尝试加载 AudioToolbox 时崩溃

xcode - IOS 13.2 (17B84) Xcode 设备支持文件

ios - Xcode 11上不存在iOS 13.1(17A844)文件夹

swiftui - 在列表下方的 SwiftUI 导航侧边栏中声明底部区域