macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

retainArguments

INDEX>Foundation>NSInvocation

起動オブジェクトが引数を保持するようにセットします

解説

起動オブジェクトが引数を保持するようにセットします。

返り値

( void )

なし

引数

クラス

NSInvocation

Instance Methods

使用可能

10.0
iOS2.0以降

参照

例文

#import "MyObject.h"
@implementation MyObject

- (IBAction)myAction:(id)sender
{
    //メソッドシグネチャ
	NSMethodSignature *aSignature ;
    
	//起動オブジェクト
	NSInvocation *invocation ;
	
	//セレクタ
    SEL aSelector ;
    
	NSString *aBuffer=@"aaa";
    
	//セレクタをセット
    aSelector  = @selector( timerControl: );
	
	//メソッドシグネチャをセット
    aSignature = [ self methodSignatureForSelector:aSelector ];
	
	//起動オブジェクトを作成
    invocation = [ NSInvocation invocationWithMethodSignature:aSignature ];
	
	//ターゲットはself
    [ invocation setTarget: self ];
	
	//セレクタをセット
    [ invocation setSelector: aSelector ];
	
	//引数をセット
    [ invocation setArgument:&aBuffer atIndex:2];
    
	//起動する
	[ invocation invoke ];

	//引数、返り値を保持
	[ invocation retainArguments];
    
	//保持するか
    if ([invocation argumentsRetained]){
		NSLog(@"YES");
    }else{
		NSLog(@"NO");
    }
}

-(NSString *) timerControl:(NSString *)arg
{
	NSLog(@"%@",arg);
	return @"OK";
}

@end