Friday, June 27, 2014

Real Russian Perl

#!/usr/blin/perl
while(true) {
    ++$i--;
}

How to redirect JavaScript console.log() to Xcode's debug output

On iOS >= 7.0 it is pretty easy thanks to brilliant (and undocumented as well) framework:
@import JavaScriptCore;

...

// get UIWebView's JavaScript context
JSContext *ctx = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

// 'listen' to console.log()
ctx[@"console"][@"log"] = ^(NSString *message) { 
    NSLog(@"Javascript's console.log() :\n%@\n\n", message); 
};