JavaScriptCore
We can easily access any values we’ve created in our
contextusing subscript notation on bothJSContextandJSValueinstances.JSContextrequires a string subscript, whileJSValueallows either string or integer subscripts for delving down into objects and arrays:
Swift doesn’t support the subscript notation, though.
With a
JSValuethat wraps a JavaScript function, we can call that function directly from our Objective-C/Swift code using Foundation types as parameters. Once again, JavaScriptCore handles the bridging without any trouble[…][…]
There are two main ways of giving a
JSContextaccess to our native client code: blocks and theJSExportprotocol.[…]
Since blocks can capture references to variables and
JSContexts maintain strong references to all their variables, some care needs to be taken to avoid strong reference cycles. Avoid capturing yourJSContextor anyJSValues inside a block. Instead, use[JSContext currentContext]to get the current context and pass any values you need as parameters.