I'm having a hard time to understand how NSViewRepresentable interacts with a SwiftUI view.
For example, in the example below, how can I load a different URL when the button in the view is clicked?
import Cocoa
import SwiftUI
import WebKit
import PlaygroundSupport
struct InternalBrowser: NSViewRepresentable {
func makeNSView(context: Context) -> WKWebView {
let browser = WKWebView()
browser.load(URLRequest(url: URL(string: "https://www.google.com")!))
return browser
}
func updateNSView(_ nsView: WKWebView, context: Context) {
}
}
struct Browser: View {
var body: some View {
GeometryReader { g in
VStack {
InternalBrowser().frame(width: 400, height: 400)
Button(action: {
// how to tell InternalBrowser to load an URL here?
}) {
Text("Load Different URL")
}
}
}
}
}
PlaygroundPage.current.setLiveView(Browser().frame(width: 500, height: 500))