简体   繁体   English

UIViewControllerRepresentable - “非最终类不能满足协议” - SwiftUI

[英]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:我试过了:

  • Switching the 'VideoAnswerViewController' for 'VideoAnswerWrapper.UIViewControllerType'为“VideoAnswerWrapper.UIViewControllerType”切换“VideoAnswerViewController”
  • Restarting Xcode, clearing caches, derived data, etc.重启Xcode,清除缓存,派生数据等。
  • Starting with a blank ViewController to ensure it's not a weird storyboard issue从一个空白的 ViewController 开始,以确保它不是一个奇怪的故事板问题
  • Switching down an Xcode version as well as trying the 11.4 beta.切换 Xcode 版本并尝试 11.4 测试版。
  • Different ways of instantiating the VideoAnswerViewController实例化 VideoAnswerViewController 的不同方式
  • Adding 'final' to the class向班级添加“final”

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.

相关问题 带有 UIViewControllerRepresentable 的 SwiftUI - SwiftUI with UIViewControllerRepresentable 在 SwiftUI 中使用 UIViewControllerRepresentable 呈现 UIDocumentInteractionController - Presenting UIDocumentInteractionController with UIViewControllerRepresentable in SwiftUI 在带有 UIViewControllerRepresentable 的 SwiftUI 应用程序中使用 qualtrics - using qualtrics in a SwiftUI app with a UIViewControllerRepresentable 如何在 SwiftUI 中隐藏 UIViewControllerRepresentable 中的 UIKit 选项卡 - How to hide UIKit Tabbar in UIViewControllerRepresentable in SwiftUI SwiftUI 大标题导航栏与 UIViewControllerRepresentable UITableViewController 的兼容性 - Compatibility between SwiftUI's large title navigation bar and UIViewControllerRepresentable UITableViewController 为没有 ViewController Delegate 的 ViewController 创建 SwiftUI UIViewControllerRepresentable - Creating a SwiftUI UIViewControllerRepresentable for a ViewController that doesn't have a ViewController Delegate swiftui TabView 在设备下呈现 UIViewControllerRepresentable 的意外行为 - Unexpected behavior with swiftui TabView presenting UIViewControllerRepresentable under device 更新@State 后未调用 SwiftUI UIViewControllerRepresentable.updateUIViewController - SwiftUI UIViewControllerRepresentable.updateUIViewController not being called after updating @State FBFinalClassViolationException:FBAdTimer 是最终类,不能被子类化 - FBFinalClassViolationException: FBAdTimer is a final class and cannot be subclassed SwiftUI 将触摸事件从 UIViewControllerRepresentable 传递到 View behind - SwiftUI passing touch events from UIViewControllerRepresentable to View behind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM