Showing posts with label Objective-C. Show all posts
Showing posts with label Objective-C. Show all posts

Friday, June 27, 2014

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); 
};

Friday, October 25, 2013

The Objective-C religion doesn't allow to insert Integers into NSDictionary

So...
// why they've done so with old good enums?
typedef NS_ENUM(NSUInteger, PaymentType) {
    tCreditCard  = 0,
    tBankAccount = 1,
    tBitcoin     = 2
};

        ...

NSDictionary *payItem = [[NSDictionary alloc] 
                        initWithObjectsAndKeys:[NSNumber numberWithInt:tCreditCard], @"type", 
                        [self makeFakeCreditCardData], @"data", nil];

        ...

switch([[object valueForKey:@"type"] integerValue])
{
    case tCreditCard:
        // do something
        break;

        ...

Tuesday, October 15, 2013

Linking Storyboards

Very "elegant" solution to resolve "We have one storyboard at all" iOS programmers group nightmare.
Yes, I'm making fun :)

Monday, October 7, 2013