SwiftUI:UIViewRepresentable 小部件预览
SwiftUI: UIViewRepresentable widget preview
要预览 UIViewRepresentable
结构,我有以下代码:
import SwiftUI
import WidgetKit
struct ViewRepresentable: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
return UIView()
}
func updateUIView(_ uiView: UIView, context: Context) {
}
typealias UIViewType = UIView
}
struct ViewRepresentable_Previews: PreviewProvider {
static var previews: some View {
ViewRepresentable().previewContext(WidgetPreviewContext(family: .systemSmall))
}
}
它输出以下诊断信息。
RemoteHumanReadableError: Failed to update preview
invalid TimelineEntries
错误是“无法在此文件中预览 – 更新预览失败”
如何解决这个错误?
UIKit views wrapped in UIViewRepresentable will not work in WidgetKit.
来源:https://developer.apple.com/forums/thread/653471?answerId=619627022#619627022
要预览 UIViewRepresentable
结构,我有以下代码:
import SwiftUI
import WidgetKit
struct ViewRepresentable: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
return UIView()
}
func updateUIView(_ uiView: UIView, context: Context) {
}
typealias UIViewType = UIView
}
struct ViewRepresentable_Previews: PreviewProvider {
static var previews: some View {
ViewRepresentable().previewContext(WidgetPreviewContext(family: .systemSmall))
}
}
它输出以下诊断信息。
RemoteHumanReadableError: Failed to update preview
invalid TimelineEntries
错误是“无法在此文件中预览 – 更新预览失败”
如何解决这个错误?
UIKit views wrapped in UIViewRepresentable will not work in WidgetKit.
来源:https://developer.apple.com/forums/thread/653471?answerId=619627022#619627022