invoke
起動オブジェクトにセットされているターゲットにメッセージを送信します
-( void )invoke
解説
起動オブジェクトにセットされているターゲットにメッセージを送信します。
このメソッドが呼び出される前に、アクションセレクタとターゲット、引数をセットしておかないといけません。
返り値
( void )
なし
引数
フレームワーク
Foundation
クラス
NSInvocation
Instance Methods
使用可能
10.0
iOS2.0以降
例文
#pragma mark NSInvocation invoke: -(void) testSelector002:(NSString *)string { NSLog(@"...call %s %@",__FUNCTION__,string); } -(void)method002 { SEL aSelector = @selector( testSelector002: );//セレクタをセット NSMethodSignature *aSignature = [ self methodSignatureForSelector:aSelector ];//セレクタのシグネチャをセット NSInvocation *aInvocation = [ NSInvocation invocationWithMethodSignature:aSignature ];//起動オブジェクトをセット //起動オブジェクトにターゲットと引数をセットする [ aInvocation setTarget: self ];//ターゲットはself [ aInvocation setSelector: aSelector ];//セレクタをセット NSArray *anArray = [[NSArray alloc] initWithObjects: @"aaa",@"bbb",@"ccc", @"ddd",@"eee",@"fff", @"ggg",@"hhh",@"iii",nil]; [anArray enumerateObjectsWithOptions:NSEnumerationConcurrent //並列 //NSEnumerationReverse //逆向き usingBlock:^(id s,NSUInteger idx,BOOL *stop){ //起動 //配列の要素を引数としてメソッドを起動する [ aInvocation setArgument:&s atIndex:2]; //-(void) testSelector002:(NSString *)stringの引数 //0 self 通常隠されている //1 _cmd 通常隠されている //2 (NSString *)string [ aInvocation invoke ];//起動する }]; //=>...call -[OOOAppDelegate testSelector002:] aaa //=>...call -[OOOAppDelegate testSelector002:] bbb //=>...call -[OOOAppDelegate testSelector002:] ccc //=>...call -[OOOAppDelegate testSelector002:] ddd //=>...call -[OOOAppDelegate testSelector002:] eee //=>...call -[OOOAppDelegate testSelector002:] fff //=>...call -[OOOAppDelegate testSelector002:] ggg //=>...call -[OOOAppDelegate testSelector002:] hhh //=>...call -[OOOAppDelegate testSelector002:] iii }