Type 'SwiftUIWebView' does not conform to protocol 'UIViewRepresentable'

181 Views Asked by At

I am a new commer, trying to create Webview with Xcode 12.0.1. I make the code identical to other comments and videos as below but I don't know why the error message "Type 'SwiftUIWebView' does not conform to protocol 'UIViewRepresentable'. Do you want to add protocol stubs?"

    import SwiftUI
import WebKit

struct SwiftUIWebView: UIViewRepresentable {
    let url: URL?
    func makeUIView(Context: Context) -> WKWebView {
        let prefs = WKWebpagePreferences()
        prefs.allowsContentJavaScript=true
        let config = WKWebViewConfiguration()
        config.defaultWebpagePreferences = prefs
        return WKWebView(
            frame: .zero,
            configuration: config
        )
    }

    
    
    func updateIUView(_ uiView: WKWebView, context: Context) {
        guard let myURL = url else {
            return
        }
        let request = URLRequest(url: myURL)
        uiView.load( request )
    }
    
}

Can you point out where is the problem and how to solve this?

0

There are 0 best solutions below