Last active
March 24, 2020 09:34
-
-
Save BrunoMiguens/52903a06f7045449e1984de10ac22d72 to your computer and use it in GitHub Desktop.
[Medium] Swift: Using Javascript library - JSContext Console Log Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import JavaScriptCore | |
let context = JSContext() | |
context?.evaluateScript("var console = { log: function(message) { _consoleLog(message) } }") | |
let consoleLog: (String) -> Void = { message in | |
print("JS Log: \(message)") | |
} | |
context?.setObject(consoleLog, forKeyedSubscript: "_consoleLog" as NSCopying & NSObjectProtocol) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment