You’re now watching this thread. If you’ve opted in to email or web notifications, you’ll be notified when there’s activity. Click again to stop watching or visit your profile to manage watched threads and notifications.
You’ve stopped watching this thread and will no longer receive emails or web notifications when there’s activity. Click again to start watching.
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!
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
import WidgetKit
import SwiftUI
struct Provider: TimelineProvider {
public typealias Entry = SimpleEntry
public func snapshot(with context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date())
completion(entry)
}
public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [SimpleEntry] = []
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
let currentDate = Date()
for hourOffset in 0 ..< 5 {
let entryDate = Calendar.current.date(byAdding: .minute, value: hourOffset, to: currentDate)!
let entry = SimpleEntry(date: entryDate)
entries.append(entry)
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
}
struct SimpleEntry: TimelineEntry {
public let date: Date
}
struct PlaceholderView : View {
var body: some View {
Text("01:05 AM\nMarch 22nd, 2020")
}
}
struct CPCWidgetEntryView : View {
var entry: Provider.Entry
let components = DateComponents(minute: 11, second: 14)
let futureDate = Calendar.current.date(byAdding : DateComponents(minute: 1, second: 0), to: Date())!
var body: some View {
ZStack {
Color(.black)
.edgesIgnoringSafeArea(.all)
VStack(alignment: .center, spacing: 0) {
Text(futureDate, style: .time)
.font(.custom("Times New Roman-bold", size: 30))
// Text(futureDate, style: .date)
// .font(.custom("Times New Roman-bold", size: 38))
//
}
.background(Color.black).foregroundColor(Color.orange)
}
}
}
@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 CPCWidget_Previews: PreviewProvider {
static var previews: some View {
/*@START_MENU_TOKEN@*/Text("Hello, World!")/*@END_MENU_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.
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. :-)
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: