Xcode preview for Widget?

Hi.
I've been trying to build a widget from the documentation and the WWDC 2020 code-along videos.

I've been trying to preview the widget in Xcode using the code from the WWDC Videos, but keep getting an "Unrecoverable error."

Is the preview working for Wigets, or is this planned for a future update?

BTW, I did try to get a copy of the error, but that doesn't seem to be working either.

Thanks,
Dan Uff
Hi Dan,

Sorry to hear you are having problems using Xcode Previews. Widget previews are working in Seed 1, so hopefully we can figure out how to make them work for you. Can you confirm that the error "unrecoverable error" is shown in the Xcode canvas?

Likely the best way for us to help you is for you to file a feedback and report back here with the ID. Make sure to include a simulator diagnosis by running simctl diagnose in the Terminal app, as well as hitting using the diagnostic bar in the canvas by hitting the "Diagnostics" button > "Generate Report". If possible a sample project goes a long way too!
Thanks for getting back to me!

The error is: “Cannot Preview in this file - Unexpected error occurred” and then the usual [Try Again] and the [Diagnostics] buttons come up.

When choosing the latter, the following error appears:

”Remote Human Readable Error:  PreviewAgentError: Statically rendering previews is not supported on iOS Simulators”

Granted, I am using the default Hello Word Placeholder in the PreviewProvider, but when I tried to change this to mirror the WWDC2020 Video Code along, I get the same error.

I am attaching the said code for the project to this message.

If you have any other questions, please let me know.

Dan Uff



}



@main

struct CPCWidget: Widget {

    private let kind: String = "CPCWidget"



    public var body: some WidgetConfiguration {

      StaticConfiguration(kind: "com.connectingpeoplesoftware.cpclockwidget",

                          provider: Provider(),

                          placeholder: PlaceholderView()) { entry in

                          CPCWidgetEntryView(entry: entry)

        }

        .configurationDisplayName("CPClock")

        .description("CPClock in widget form.")

      .supportedFamilies([.systemSmall, .systemMedium, .systemLarge])

      

    }

  

}



struct CPCWidgetPreviews: PreviewProvider {

  static var previews: some View {

    /*@START
MENUTOKEN@*/Text("Hello, World!")/*@ENDMENU_TOKEN@*/

  }

}
```

I am also having problems with getting Swift views to preview correctly. The error I am seeing is:

”Remote Human Readable Error: PreviewAgentError: Statically rendering previews is not supported on iOS Simulators”

I don't have any problems at all with previews in small, toy apps, but inside my real, actual project views don't render. Widgets can generate previews most of the time, but plain, non-widget views will not ever render. I have to develop my views in a separate project and them copied them over to the main project once they are mostly done.
Glad to see I’m not the only one.

Do what I did, file a bug report via the feedback app. Maybe if they get enough people, they can find an answer and people like us can keep our hair. :-)

Dan
Having the same issue, I end up having to run the widget to be able to see what I am working on.

Gave up on canvas a little.
If you're seeing the Statically rendering previews is not supported on iOS Simulators error, you can add a WidgetPreviewContext to your view to preview it:

Code Block swift
struct CPCWidget_Previews: PreviewProvider {
static var previews: some View {
Text("Hello, World!")
.previewContext(WidgetPreviewContext(family: .systemSmall))
}

Xcode preview for Widget?
 
 
Q