Skip to content

Instantly share code, notes, and snippets.

@thewh1teagle
Created January 28, 2024 08:09
Show Gist options
  • Save thewh1teagle/0212927f43c4328fe9cbcefed46637f0 to your computer and use it in GitHub Desktop.
Save thewh1teagle/0212927f43c4328fe9cbcefed46637f0 to your computer and use it in GitHub Desktop.
Simple swift webview (don't forget to allow outgoing and incoming internet in capabilities settings)
import SwiftUI
import WebKit
struct WebView: NSViewRepresentable {
let request: URLRequest
func makeNSView(context: Context) -> WKWebView {
return WKWebView()
}
func updateNSView(_ nsView: WKWebView, context: Context) {
nsView.load(request)
}
}
struct ContentView: View {
var body: some View {
WebView(request: URLRequest(url: URL(string: "https://google.com")!))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment