Even-easier NSInvocation creation thanks to blocks
Objective-C
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
NSInvocation+blocks.h
NSInvocation+blocks.m Added support for MRC and ARC. Feb 17, 2013
README.markdown

README.markdown

NSInvocation+blocks

Inspired by Jonathan Wight's CInvocationGrabber and Dave Dribin's DDInvocationGrabber, I realized Objective-C's newish support for blocks could make generating NSInvocations even easier.

Let's have a bake-off!

Manual:

NSInvocation *theInvocation = [NSInvocation invocationWithMethodSignature:[theString methodSignatureForSelector:@selector(insertString:atIndex:)]];
[theInvocation setSelector:@selector(insertString:atIndex:)];
[theInvocation setTarget:theString];
NSString *theFirstArgument = "Hello World";
[theInvocation setArgument:&theFirstArgument atIndex:2];
unsigned theSecondArgument = 42;
[theInvocation setArgument:&theFirstArgument atIndex:3];

Ick.

CInvocationGrabber:

CInvocationGrabber *theGrabber = [CInvocationGrabber invocationGrabber];
[[theGrabber prepareWithInvocationTarget:theString] insertString:@"Hello World" atIndex:42];
NSInvocation *theInvocation = [theGrabber invocation];

Much nicer.

NSInvocation+blocks:

NSInvocation *theInvocation = [NSInvocation jr_invocationWithTarget:theString block:^(id theString){
	[theString insertString:@"Hello World" atIndex:42];
}];

Butter.