Created by Jamz Tang at 30 September 2013

Observes what's encoded in an NSCoder object

Sometimes you're wondering what are stored in an NSCoder instance?

Here's a little utility exactly for this purpose, I called it UINibDecoderProxy. This is how you use it:

#import "UINibDecoderProxy.h"

// Then override initWithCoder:
- (id)initWithCoder:(NSCoder *)aDecoder {
   self = [super initWithCoder:[[UINibDecoderProxy alloc] initWithTarget:aDecoder]];
   return self;
}

Now go to UINibDecoderProxy.m and set a break point at -[UINibDecoderProxy forwardInvocation:] and log the necessary information for you. Notice at the inline comment below:

/*
 * This file is part of the http://ioscodesnippet.com
 * (c) Jamz Tang <jamz@jamztang.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

#import "UINibDecoderProxy.h"

@implementation UINibDecoderProxy {
    NSUInteger numberOfArguments;
}

- (id)initWithTarget:(id)target {
    _target = target;
    return self;
}

- (void)forwardInvocation:(NSInvocation *)invocation {

    // Set a breakpoint here add action "po invocation"

    for (NSUInteger i = 2; i < numberOfArguments; i++) {
        id argumment = nil;
        [invocation getArgument:&argumment atIndex:i];
        NSLog(@"argument %d %@", i, argumment);
    }
    [invocation invokeWithTarget:_target];
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel {
    NSMethodSignature *methodSignature = [_target methodSignatureForSelector:sel];

    numberOfArguments = [methodSignature numberOfArguments];

    return methodSignature;
}

@end

Hopefully not too tricky.


Installation

Using CocoaPods: [?]
pod 'UINibDecoderProxy', '~> 0.0.1'

Clone this repository:
git clone git://gist.github.com/4466616.git UINibDecoderProxy

Download | More...


If you think this is useful, share this article with your friends :)

blog comments powered by Disqus

ioscodesnippet.com