Created by Jamz Tang at 30 September 2013
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.
Using CocoaPods: [?]
pod 'UINibDecoderProxy', '~> 0.0.1'
Clone this repository:
git clone git://gist.github.com/4466616.git UINibDecoderProxy
If you think this is useful, share this article with your friends :)
blog comments powered by DisqusUINibDecoderProxy Observes what's encoded in an NSCoder object
JTKeyValueObserver Revisiting KVO+Block, the simplest version.
MethodSwizzle Method Swizzling in Objective-C
UITableViewDeleteActionResponder Quick hack to enable delete menu item in UITableView menuController
UIApplicationAddition Quickly switch supported UIInterfaceOrientation for your View Controllers
JTTargetActionBlock Adding Block support for UIControl's Target-Action mechanism
NSArray-JTArraySplit Splitting an array to several components
UIImage+JTImageDecode Force decompressing UIImage in background to achieve better performance
UINavigationBar-JTDropShadow Adding drop shadow on UINavigationBar (before iOS 6)
UIImage-JTImageCrop Crop an image in specific rect
UIView+JTRemoveAnimated Adding fadeout effect to any -[UIViews removeFromSuperview]
JTStringAddition NSStringf. Simpler printf styled +[NSString stringWithFormat:]
UIView-JTViewToImage Rendering any UIViews into UIImage in one line (updated with iOS 7 support)
NSObject-JTNibLoader Loading a Nib file programmatically using NSObject category
UIImage-JTColor Creating a placeholder UIImage dynamically with color
NSObject-JTCancelableScheduledBlock Cancelable Scheduled Blocks in Objective-C