I am working on passing data from swift to javascript inside WKWebView
I have a custom class:
class AllInfo: AnyObject {
var title = "Special Title"
var description = "Special Description"
}
and initialize it
var info = AllInfo()
Then I have a WKWebView with which I pass WKUserScript with which I have a source property:
source: "changeDisplay('\(info)')"
My problem is how to access this object in javascript. I tried to access it as a javascript object, as well as an associative array with no luck. Here's js funciton:
function changeDisplay(passedInfo) {
document.querySelector('h1').innerHTML = passedInfo.title
document.querySelector('h2').innerHTML = passedInfo.description
}
setTimeout(function () {changeDisplay();}, 5000);
EDIT: When I try to access an object like this, I get undefined.
So my questions are:
Can I pass AnyObject to JavaScript and access it? If not, what type should I do for the quick class so that I can pass it easily.
javascript swift , , .
EDIT: , JSON .