간단한 예제..
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
#import <foundation/foundation.h> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSString *prose = @"Do nine men interpret?"; | |
NSMethodSignature *signature; | |
NSInvocation *invocation; | |
NSString *count; | |
signature = [prose methodSignatureForSelector:@selector(substringWithRange:)]; | |
invocation = [NSInvocation invocationWithMethodSignature:signature]; | |
[invocation setSelector:@selector(substringWithRange:)]; | |
NSRange range = NSMakeRange(3,4); | |
[invocation setArgument:&range atIndex:2]; | |
[invocation invokeWithTarget:prose]; | |
[invocation getReturnValue:&count]; | |
NSLog(@"%@ men, I nod.", count); | |
} | |
return 0; | |
} |
NSMethodSignature의 객체를 생성 할 때 셀렉터를 지정하는데 NSInvocation의 객체를 생성 할 때도
셀렉터를 set해줘야 함... signature는 특정 셀렉터와 연결되는 것이 아니라 구성의 정보만 가지고 있는 상태라
그렇다고 함....