I am trying to use jQuery functions in JavaScriptCore, so I have executed the jQuery library as a script in my JSContext. However, after I do that, I still can't access any jQuery functions. Here's a stripped-down version of my code in a Xcode playground:
import JavaScriptCore
let context = JSContext()
//Evaluate JQuery library in context:
do {
let libString = try String(contentsOf: URL(string: "http://code.jquery.com/ui/1.9.2/jquery-ui.js")!, encoding: .utf8)
context?.evaluateScript(libString)
} catch (let error) {
print("Error while processing URL: \(error)")
}
//Access variables defined by JQuery library:
print("'$' in context is defined as: \(context?.objectForKeyedSubscript("$"))")
print("'jQuery' in context is defined as: \(context?.objectForKeyedSubscript("jQuery"))")
This prints:
'$' in context is defined as: Optional(undefined)
'jQuery' in context is defined as: Optional(undefined)
If I had included the library correctly, those would be defined as functions. What have I done wrong? Should I even be using JavaScriptCore to gain jQuery functionality?