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
 * (c) Jamz Tang <[email protected]>
 * 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;


Hopefully not too tricky.


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

Clone this repository:
git clone git:// UINibDecoderProxy

| More...

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

blog comments powered by Disqus