UIViewRepresentable is not working

I have been trying to integrate a UIKit view into SwiftUI, specifically a WKWebView. However, I keep encountering a does not conform to protocol error.

Here's my code:

import SwiftUI
import WebKit

struct SimpleWebView: View {
    var body: some View {
        WebViewContainerRepresentable()
            .edgesIgnoringSafeArea(.all)
    }
}

struct WebViewContainerRepresentable: UIViewRepresentable {
    typealias UIViewType = WKWebView
    func makeUIView(context: Context) -> WKWebView {
        let webView = WKWebView()
        if let url = Bundle.main.url(forResource: "index", withExtension: "html") {
            webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent())
        }
        return webView
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {
        // Updates not required for this use case
    }
}

I tried this with other views as well, and it turns out this is not WKWebView-specific.

The minimum deployment version is iOS 15.

Any help would be much appreciated. Let me know if I need to add any more information.

I tested this part of code, with no error, as long as you include the updateUIView function, even empty.

struct WebViewContainerRepresentable: UIViewRepresentable {

    typealias UIViewType = WKWebView

    func makeUIView(context: Context) -> WKWebView {
        let webView = WKWebView()
        if let url = Bundle.main.url(forResource: "index", withExtension: "html") {
            webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent())
        }
        return webView
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {
        // Updates not required for this use case
    }
}
UIViewRepresentable is not working
 
 
Q