Home > Net >  Type 'VideoView' does not conform to protocol 'UIViewRepresentable'
Type 'VideoView' does not conform to protocol 'UIViewRepresentable'

Time:08-21

I'm trying to embed a YouTube video into my app and keep getting this error Type 'VideoView' does not conform to protocol 'UIViewRepresentable'

here's my code:

import SwiftUI
import WebKit

struct VideoView: UIViewRepresentable {
    
    let videoID: String
    
    func makeUIView(context: Context) -> some WKWebView {
        return WKWebView()
    }
    
    func updateUIView(_ uiView: WKWebView, context: Context) {
        guard let youtubeURL = URL(string: "https://www.youtube.com/embed/\(videoID)") else {return}
        uiView.scrollView.isScrollEnabled = false
        uiView.load(URLRequest(url: youtubeURL))
    }
}

thanks.

CodePudding user response:

Remove some from return type

func makeUIView(context: Context) -> WKWebView {   // << here !!
    return WKWebView()
}
  • Related