Skip to content

Instantly share code, notes, and snippets.

@szastupov
Created July 9, 2017 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szastupov/3d18e37865974cc4f9fd74fdcff3f88e to your computer and use it in GitHub Desktop.
Save szastupov/3d18e37865974cc4f9fd74fdcff3f88e to your computer and use it in GitHub Desktop.
console.log() for jscore in swift
context.evaluateScript("var console = { log: function(...args) { _consoleLog(args.join(' ')) } }")
let consoleLog: @convention(block) (String) -> Void = { message in
print("console.log: " + message)
}
context.setObject(unsafeBitCast(consoleLog, to: AnyObject.self), forKeyedSubscript: "_consoleLog" as (NSCopying & NSObjectProtocol)!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment