Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JSContext subscript access for Swift (works like Objective-C JSContext subscript)
extension JSContext {
subscript(_ get: String) -> JSValue! {
get {
return self.objectForKeyedSubscript(get)
}
set { fatalError("get: cannot be used to set") }
}
subscript(_ set: String) -> Any! {
set {
self.setObject(newValue, forKeyedSubscript: set as NSString)
}
get { fatalError("set: cannot be used to get") }
}
}
@jasonm23

This comment has been minimized.

Copy link
Owner Author

@jasonm23 jasonm23 commented May 14, 2018

let ctx = JSContext()

ctx["myThing"] = "This is my string thing"
let myThingString = ctx["myThing"].toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment