macOS/iOS API解説

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

目次

getReturnValue:

INDEX>Foundation>NSInvocation

起動オブジェクトを起動した後の戻り値をバッファに入れます
-(void)getReturnValue:(void *)buffer:

解説

起動オブジェクトを起動した後の戻り値をバッファに入れます。
起動オブジェクトを起動ていない場合、戻り値は定義されていません。
バッファに必要なサイズを決めるためにはNSMethodSignatureのmethodReturnLengthメソッドを使用します。

unsigned int length = [[anInvocation methodSignature] methodReturnLength];
buffer = (void *)malloc(length);

返り値

( void )

なし

引数

( void * )buffer

バッファのポインタ

クラス

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 retainArguments];
	//バッファのサイズを調べる
	unsigned int length = [[invocation methodSignature] methodReturnLength];
	//バッファ確保
	void * buffer = (void *)malloc(length);
	
	//起動する
    [ invocation invoke ];
	
	//返り値を保持
    [ invocation getReturnValue:&buffer];
    
	//返り値を表示
	NSLog(buffer);
}

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

@end