Skip to content

Instantly share code, notes, and snippets.

@awunnenb
Created October 7, 2020 20:28
Show Gist options
  • Save awunnenb/b5b5350955f9270b209b3010aa81c968 to your computer and use it in GitHub Desktop.
Save awunnenb/b5b5350955f9270b209b3010aa81c968 to your computer and use it in GitHub Desktop.
WKWebView
import SwiftUI
import WebKit
struct ContentView: View {
let webView = WebView(request: URLRequest(url: URL(string: "https://www.google.com")!))
var body: some View {
VStack {
webView
}
}
}
struct WebView: UIViewRepresentable {
let request: URLRequest
private var webView: WKWebView?
init(request: URLRequest) {
self.webView = WKWebView()
self.request = request
}
func makeUIView(context: Context) -> WKWebView {
return webView!
}
func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.load(request)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment