【问题标题】:SwiftUI Preview displays error - Cannot preview in this file -- current target needs adjusted build settingsSwiftUI Preview 显示错误 - 无法在此文件中预览 - 当前目标需要调整构建设置
【发布时间】:2019-11-01 02:21:35
【问题描述】:

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

无法在此文件中预览——当前目标需要调整构建设置

随着

"ProjectTests.xctest' 未能获得构建 设置: unsupportedProductType("com.apple.product-type.bundle.unit-test",

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

打开的文件支持构建设置 “ProjectTests.xctest”未能获取构建设置:unsupportedProductType("com.apple.product-type.bundle.unit-test", <0xblahblahblahprojecttests.xctest blueprint:>

    标签: swiftui xcode11 xcode11.1


    【解决方案1】:

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

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

    Xcode 版本 11.1 (11A1027)

    【讨论】:

    • 谢谢@Asperi!我已经尝试过.previewLayout(.device).previewDevice("iPhone 11") 以及选择特定设备而不是“通用 iOS 设备”,但没有发现变化。
    【解决方案2】:

    Xcode 版本 11.2 (11B52) 中不再存在此错误。

    【讨论】:

    • XCode Version 11.3 (11C29) 中仍然存在错误
    猜你喜欢
    • 2020-07-10
    • 1970-01-01
    • 2022-01-25
    • 2019-10-20
    • 2020-03-16
    • 2020-02-13
    • 1970-01-01
    • 2021-06-10
    • 2022-12-02
    相关资源
    最近更新 更多