SwiftUI Preview displays error - Cannot preview in this file -- current target needs adjusted build settings

3k Views Asked by At

I'm using Xcode 11.1 and all of my swift previews show the following errors:

swiftui preview pane error

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

along with

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

Clicking the diagnostics button generates the following popup:

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>>)

My previews still render fine, but is there some way to remove this error?

2

There are 2 best solutions below

1
On BEST ANSWER

This error no longer exists in Xcode Version 11.2 (11B52).

1
On

Change Destination to some Simulator instead of "iOS Generic Device" or in preview provider specify preview device explicitly, like

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

Xcode Version 11.1 (11A1027)