Created
December 25, 2013 12:54
-
-
Save alvesjtiago/8123006 to your computer and use it in GitHub Desktop.
Create invocations the simple way. Extracted from ITActionManager.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSInvocation+SimpleCreation.h | |
// MAPI | |
// | |
// Created by Tiago Alves on 08/12/13. | |
// Copyright (c) 2013 Iterar. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSInvocation (SimpleCreation) | |
+ (NSInvocation*)invocationWithTarget:(id)target andSelector:(SEL)selector; | |
+ (NSInvocation*)invocationWithTarget:(id)target selector:(SEL)selector andArguments:(NSArray*)arguments; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSInvocation+SimpleCreation.m | |
// MAPI | |
// | |
// Created by Tiago Alves on 08/12/13. | |
// Copyright (c) 2013 Iterar. All rights reserved. | |
// | |
#import "NSInvocation+SimpleCreation.h" | |
@implementation NSInvocation (SimpleCreation) | |
+ (NSInvocation*)invocationWithTarget:(id)target andSelector:(SEL)selector { | |
NSMethodSignature *sig = [[target class] instanceMethodSignatureForSelector:selector]; | |
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig]; | |
[inv setTarget:target]; | |
[inv setSelector:selector]; | |
return inv; | |
} | |
+ (NSInvocation*)invocationWithTarget:(id)target selector:(SEL)selector andArguments:(NSArray *)arguments { | |
NSInvocation *inv = [NSInvocation invocationWithTarget:target andSelector:selector]; | |
int argumentIndex = 2; | |
for (int i = 0; i < arguments.count; i++) { | |
id argument = [arguments objectAtIndex:i]; | |
[inv setArgument:&argument atIndex:argumentIndex]; | |
argumentIndex += 1; | |
} | |
[inv retainArguments]; | |
return inv; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment