Patching console.log into Swift's JavaScriptCore JSContext
By default, you cannot print to the Xcode console from within a JavaScriptCore-evaluated script. print
, echo
, console.log
– nothing of the like is available. Caveman debugging is tremendously useful, though, so we all know that we want to print from the JavaScript we evaluat, right?
Add Subscripts to JavaScriptCore Types in Swift
The JavaScriptCore framework was apparently very convenient to use in Objective-C times: you could simply use subscripts to change objects inside the context, like this: In Swift, tutorials you find on the web stick to the longer version that underlies the subscript convention here: method calls to -objectForKeyedSubscript
and -setObject:forKeyedSubscript:
.