-
-
Save winterdl/0654c6e83eb60c695641f7259da86a7d 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