我使用的是 Xcode 11.1,我所有的 swift 预览都显示以下错误:
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..."
单击诊断按钮会生成以下弹出窗口:
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/