SwiftUI question: (How) Can the myClass instance in this View interact with a State variable?
Not working:
by the way, I’m adding myClass to a webview’s configuration.userContentController. The userContentController in the class gets called when javascript calls window.webkit.messageHandlers.hello.postMessage("new world")
Thank you kindly
Not working:
Code Block struct MyView: View { @State private var hello = "world" let myClass = MyClass() class MyClass: NSObject, WKScriptMessageHandler { func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { if message.name == "hello"{ hello = message.body } } // ... }
by the way, I’m adding myClass to a webview’s configuration.userContentController. The userContentController in the class gets called when javascript calls window.webkit.messageHandlers.hello.postMessage("new world")
Thank you kindly