Skip to content

Instantly share code, notes, and snippets.

@gewill
Created November 29, 2022 15:19
Show Gist options
  • Save gewill/b80bb49e4085a48813760b759e23c7f6 to your computer and use it in GitHub Desktop.
Save gewill/b80bb49e4085a48813760b759e23c7f6 to your computer and use it in GitHub Desktop.
WebView for macOS in SwiftUI
import SwiftUI
import WebKit
struct WebView: NSViewRepresentable {
typealias NSViewType = WKWebView
var html: String
func makeNSView(context: Context) -> WKWebView {
return WKWebView()
}
func updateNSView(_ nsView: WKWebView, context: Context) {
nsView.loadHTMLString(html, baseURL: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment