The following piece of code works like a charm to define a function in Swift (2.0) that I can call from a Javascript resource (tvos). The function storeSetPackageInfo accepts a parameter and returns nothing.
I am trying to understand how I achieve the same goal with a function that accept no parameters and returns a boolean. I don't seem to understand the syntax.
private typealias JavascriptClosure = (JSContext) -> Void
private typealias ObjectivecCompletionBlock = @convention(block) (String) -> Void
func setupStoreSetPackageInfo() {
let selectComponent: JavascriptClosure = {
[unowned self](context: JSContext) -> Void in
let objCompletion: ObjectivecCompletionBlock = {
(str: String) -> Void in
(self.delegate as? myTVAppControllerDelegate)?.storeSetPackageInfo(str)
}
context.setObject(unsafeBitCast(objCompletion, AnyObject.self), forKeyedSubscript: "storeSetPackageInfo")
}
evaluateInJavaScriptContext(selectComponent, completion: nil)
}
I tried multiple approaches which compile but resulting in the JSContext in not finding the function. Any help is very appreciated.