Created
October 13, 2014 09:38
-
-
Save xpqz/01ee8c074338c0b80a7d to your computer and use it in GitHub Desktop.
JavaScript from Swift
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 Foundation | |
import JavaScriptCore | |
public class GeoWrapper { | |
var jsContext: JSContext | |
public init?() { | |
jsContext = JSContext() | |
jsContext.exceptionHandler = { NSLog("ERROR: '%@'", $1) } | |
if let path = NSBundle(forClass:GeoWrapper.self).pathForResource("GeoFunctions", ofType: "js") { | |
let content = NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding, error: nil) | |
let jsval = jsContext.evaluateScript(content) | |
} else { | |
return nil | |
} | |
} | |
public func convertOSGridRefToWSGS84(gridref: String) -> String? { | |
if let jsFunction = jsContext.objectForKeyedSubscript("convert") { | |
if let value = jsFunction.callWithArguments([ gridref ]) { | |
return value.toString() | |
} | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment