I have this simple view.
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Usually this previews fine. But today, I get this error Unknown preview provider "ContentView_Previews_":
Pressing Try Again doesn't work. When I press Diagnostics, this shows up:
RemoteHumanReadableError: Failed to update preview.
Error encountered when sending 'previewInstances' message to agent.
==================================
| RemoteHumanReadableError: Unknown preview provider "ContentView_Previews_"
|
| 5SwiftUI does not contain a preview provider named "ContentView_Previews_". Check your build settings to ensure the preview provider is compiled into your product.
|
| Mangled name: 009_SwiftUI_0021ContentView_Previews_V
So I thought maybe Xcode is glitching out and wants an underscore at the end of the preview struct. I added that:
struct ContentView_Previews_: PreviewProvider {
But now I get, Unknown preview provider "ContentView_Previews__
.
Is anyone else coming across this? My Xcode version is Version 12.3 (12C33).
I had the very same problem. Eventually, I figured out that this happens when the project name starts with a number character, e.g. "01-test"
. Creating a new project without the digit as a first character works just fine, e.g. "test"
.
None of above answer worked for me so after a lot of trying I found out that my preview struct that conforms to PreviewProvider
is private. That solved my issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With