Created
June 25, 2015 19:40
-
-
Save adamloving/da5fc0917cb5f0d22519 to your computer and use it in GitHub Desktop.
running Javascript from Swift using JavaScriptCore (try this in a playground)
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 num = 5 + 5") | |
context.evaluateScript("var names = ['Grace', 'Ada', 'Margaret']") | |
context.evaluateScript("var triple = function(value) { return value * 3 }") | |
context.evaluateScript("names.sort()") | |
let tripleNum: JSValue = context.evaluateScript("triple(num)") | |
let x = context.evaluateScript( | |
"x = {a: 1, b: ['blah'], c: { cat: 1.0 }}") | |
x.valueForProperty("a") | |
x.valueForProperty("b") | |
let o: JSValue = x.valueForProperty("c") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forked from http://nshipster.com/javascriptcore/