Skip to content

Instantly share code, notes, and snippets.

@activcoding
Forked from joshbetz/Webview.swift
Created August 24, 2021 18:47
Show Gist options
  • Save activcoding/f79bc8f6db3f41e87e21150da53e6eb3 to your computer and use it in GitHub Desktop.
Save activcoding/f79bc8f6db3f41e87e21150da53e6eb3 to your computer and use it in GitHub Desktop.
A simple SwiftUI Webview
import SwiftUI
import WebKit
struct ContentView: View {
var body: some View {
Webview(url: URL(string: "https://google.com")!)
}
}
struct Webview: UIViewRepresentable {
let url: URL
func makeUIView(context: UIViewRepresentableContext<Webview>) -> WKWebView {
let webview = WKWebView()
let request = URLRequest(url: self.url, cachePolicy: .returnCacheDataElseLoad)
webview.load(request)
return webview
}
func updateUIView(_ webview: WKWebView, context: UIViewRepresentableContext<Webview>) {
let request = URLRequest(url: self.url, cachePolicy: .returnCacheDataElseLoad)
webview.load(request)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment