I am trying to preview some View by using Widget context, like:
struct MyTasksView_Previews: PreviewProvider {
static var previews: some View {
MyTasksView(
myTasks: Fake.myTasks,
user: Fake.user,
error: ""
)
.previewContext(WidgetPreviewContext(family: .systemMedium))
}
}
However, I'm getting this error while attempt to run the preview. And, I'm not sure why it is happing.
RemoteHumanReadableError: Unknown preview provider “MyTasksView_Previews” MyApp does not contain a preview provider named “MyTasksView_Previews”. Check your build settings to ensure the preview provider is compiled into your product.
I, also, tried to use a simple Text(text).previewContext(WidgetPreviewContext(family: .systemMedium))
, but it did not work either. I'm using the Xcode beta 5.
In Apple Emoji Rangers Demo App for WWDC 2020. We can see this piece of code for preview:
struct CharacterNameView_Previews: PreviewProvider {
static var previews: some View {
CharacterNameView(CharacterDetail.panda)
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}
Add
Widget extension
target, and activate it. For more information https://developer.apple.com/documentation/widgetkit/creating-a-widget-extension