Created
May 27, 2019 14:29
-
-
Save BrunoMiguens/ca3e84dfee22d8ec5cb68ae81192ea33 to your computer and use it in GitHub Desktop.
[Medium] Swift: Using Javascript library - Load JS Code and Parse File
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
let context = generateJSContext() | |
loadJSBundle(for: context) | |
if let csonPath = Bundle.main.path(forResource: "cson-sample", ofType: "cson"), let csonData = try? String(contentsOfFile: csonPath) { | |
context?.setObject(csonData, forKeyedSubscript: "parseStringData" as NSCopying & NSObjectProtocol) | |
let jsonData = context?.evaluateScript("CSON.parse(parseStringData)")?.toDictionary() | |
print(jsonData?.description ?? "") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment