How to call JavaScript function from Swift TVOS/TVMLJS

By calling this function popTemplateFromNavigationStack from Swift

Code Block
func popTemplateFromNavigationStack() {
      appDelegate.appController?.evaluate(inJavaScriptContext: {(evaluation: JSContext) -> Void in
      let popTemplateFromNavigationStack =
evaluation.objectForKeyedSubscript("popTemplateFromNavigationStack")
      let _ = popTemplateFromNavigationStack?.call(withArguments: ["REFRESH"])
    }, completion: {(Bool) -> Void in
      //evaluation block finished running
    })
  }


I would expect it to call the popTemplateFromNavigationStack function in my app.js file

Code Block
const popTemplateFromNavigationStack = () => {
  console.log("POP TEMPLATE FROM NAV STACK")
}


But instead I get the following error log

Code Block
[System] <IKAppContext (0): 0x6000005f0a80> Error: undefined is not an object - undefined - line:undefined:undefined

How to call JavaScript function from Swift TVOS/TVMLJS
 
 
Q