Created
November 9, 2020 13:57
-
-
Save sjordine/ad18b3594f9cb72a15dd1a100fcb86d1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| if let context = JSContext() { | |
| let asynchronousCall: @convention(block) (JSValue) -> Void = { (callback) in | |
| loadCatFact { (catFact) in | |
| callback.call(withArguments: [catFact]) | |
| } | |
| } | |
| let printText:@convention(block) (String) -> Void = { (text) in | |
| print("\(text)") | |
| } | |
| context.setObject(asynchronousCall, | |
| forKeyedSubscript: "loadFact" as NSString) | |
| context.setObject(printText, | |
| forKeyedSubscript: "print" as NSString) | |
| let result = context.evaluateScript(""" | |
| print("before"); | |
| loadFact(result => { | |
| print("Raw data: " + result); | |
| fact = JSON.parse(result); | |
| print("Fact: " + fact.fact); | |
| }); | |
| print("after"); | |
| """) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment