The following code is how to call Javascript functions from Swift
if let jsSourcePath = Bundle.main.path(forResource: "jssrc", ofType: "js"){
do {
let jsSourceContents = try String(contentsOfFile: jsSourcePath)
self.jsContext.evaluateScript(jsSourceContents)
}
catch {
print(error.localizedDescription)
}
I thought I could do something similar for jquery. I have an identical codeblock to the one above, the only difference is I specify the official jquery library to evaluate.
I get the following error when I try to evaluate jquery.js, however.
TypeError: undefined is not an object (evaluating 'document.createElement')
Why is document.createElement resolving to undefined? Do I need to modify the class jsContext is a member of, such that the view is a WKWebView?