[英]SwiftUI: UIViewRepresentable widget preview
To get a preview of a UIViewRepresentable
struct, I have the following code:要预览
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))
}
}
It outputs the following diagnostics.它输出以下诊断信息。
RemoteHumanReadableError: Failed to update preview
invalid TimelineEntries
The error is "Cannot preview in this file – Failed to update preview"错误是“无法在此文件中预览 - 无法更新预览”
How do you solve this error?你如何解决这个错误?
UIKit views wrapped in UIViewRepresentable will not work in WidgetKit.
包裹在 UIViewRepresentable 中的 UIKit 视图在 WidgetKit 中不起作用。
Source: https://developer.apple.com/forums/thread/653471?answerId=619627022#619627022来源: https : //developer.apple.com/forums/thread/653471?answerId=619627022#619627022
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.