Skip to content

Instantly share code, notes, and snippets.

@md2k
Forked from rayh/Example.swift
Created January 20, 2016 19:09
Show Gist options
  • Save md2k/73af28d0d0c73deb80b3 to your computer and use it in GitHub Desktop.
Save md2k/73af28d0d0c73deb80b3 to your computer and use it in GitHub Desktop.
Setup console.log() for TVJS apps
func appController(appController: TVApplicationController, evaluateAppJavaScriptInContext jsContext: JSContext) {
jsContext.evaluateScript("var console = {log: function() { var message = ''; for(var i = 0; i < arguments.length; i++) { message += arguments[i] + ' ' }; console.print(message) } };")
let logFunction: @convention(block) (NSString!) -> Void = { (message:NSString!) in
print("JS: \(message)")
}
jsContext.objectForKeyedSubscript("console").setObject(unsafeBitCast(logFunction, AnyObject.self), forKeyedSubscript:"print")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment