Skip to content

Instantly share code, notes, and snippets.

@pietrorea
Created December 7, 2014 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pietrorea/8309d74336bd82c127ae to your computer and use it in GitHub Desktop.
Save pietrorea/8309d74336bd82c127ae to your computer and use it in GitHub Desktop.
Cast Swift closure as Objective-C block (needed for JavaScriptCore)
var block : @objc_block (NSString!) -> Void = {
[unowned self] (string : NSString!) -> Void in
let jsText = "\(string)\n"
self.outputTextView.setText(jsText, concatenate: true)
}
context.setObject(unsafeBitCast(block, AnyObject.self),
forKeyedSubscript: "print")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment