[英]UIViewControllerRepresentable - "Protocol cannot be satisfied by a non-final class" - SwiftUI
Not sure if I'm missing something or found a SwiftUI bug.不确定我是否遗漏了什么或发现了 SwiftUI 错误。 This is such a simple thing and it's driving me crazy.
这是一件如此简单的事情,它让我发疯。
Trying to setup a UIViewControllerRepresentable but getting the following errors:尝试设置 UIViewControllerRepresentable 但出现以下错误:
Protocol 'View' requirement '_makeView(view:inputs:)' cannot be satisfied by a non-final class ('VideoAnswerWrapper') because it uses 'Self' in a non-parameter, non-result type position
协议 'View' 要求 '_makeView(view:inputs:)' 不能被非最终类 ('VideoAnswerWrapper') 满足,因为它在非参数、非结果类型位置使用了 'Self'
Protocol 'View' requirement '_makeViewList(view:inputs:)' cannot be satisfied by a non-final class ('VideoAnswerWrapper') because it uses 'Self' in a non-parameter, non-result type position
协议 'View' 要求 '_makeViewList(view:inputs:)' 不能被非最终类 ('VideoAnswerWrapper') 满足,因为它在非参数、非结果类型位置使用了 'Self'
I've tried:我试过了:
Here is my UIViewControllerRepresentable class:这是我的 UIViewControllerRepresentable 类:
import SwiftUI
class VideoAnswerWrapper: UIViewControllerRepresentable {
typealias UIViewControllerType = VideoAnswerViewController
private var question : Question!
init(question: Question?) {
guard let question = question else {fatalError()}
self.question = question
}
func makeUIViewController(context: UIViewControllerRepresentableContext<VideoAnswerWrapper>) -> VideoAnswerViewController {
let storyboard = UIStoryboard(name: "VideoAnswer", bundle: .main)
//Downcast returned controller to the requried type
guard let viewController = storyboard.instantiateInitialViewController() as? VideoAnswerViewController else { fatalError() }
//Assign selected question object to instance property on incoming viewController.
// viewController.question = question
return viewController
}
func updateUIViewController(_ uiViewController: VideoAnswerViewController, context: UIViewControllerRepresentableContext<VideoAnswerWrapper>) {
}
}
UIViewController (I've stripped all the functionality to isolate the bug) UIViewController(我已经剥离了所有功能以隔离错误)
import UIKit
class VideoAnswerViewController: UIViewController {
}
class VideoAnswerWrapper: UIViewControllerRepresentable { typealias UIViewControllerType = VideoAnswerViewController
The above intended to present a SwiftUI View
so MUST be a struct as below以上旨在呈现 SwiftUI
View
因此必须是如下结构
struct VideoAnswerWrapper: UIViewControllerRepresentable {
typealias UIViewControllerType = VideoAnswerViewController
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.