Skip to content

rentzsch/NSInvocation-blocks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

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.

About

Even-easier NSInvocation creation thanks to blocks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •