macOS/iOS API解説

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

目次

methodSignature

INDEX>Foundation>NSInvocation

起動オブジェクトのメソッドシグネチャを返します

解説

起動オブジェクトのメソッドシグネチャを返します。
メソッドシグネチャとは、引数と返り値のセット
たとえば-(BOOL)updateAppointmentsForDate:(Date *)aDateというメソッドの場合
メソッドシグネチャはBOOLとDate *

返り値

( NSMethodSignature * )

メソッドシグネチャ

引数

クラス

NSInvocation

Instance Methods

使用可能

10.0
iOS2.0

参照

例文

#import "MyObject.h"
@implementation MyObject

NSTimer *timer=nil;

- (IBAction)myAction:(id)sender
{
	//メソッドシグネチャ
	NSMethodSignature *aSignature ;
    
	//起動オブジェクト
	NSInvocation *invocation ;

	//セレクタ
    SEL aSelector  = @selector( timerControl: );
	
	//メソッドシグネチャ
    aSignature = [ self methodSignatureForSelector:aSelector ];
	
	//起動オブジェクトをセット
    invocation = [ NSInvocation invocationWithMethodSignature:aSignature ];
	
	//ターゲットはself
    [ invocation setTarget: self ];
	
	//セレクタをセット
    [ invocation setSelector: aSelector ];
	
	//起動する
    [ invocation invoke ];
	
    NSLog(@"Signature number %d",[[invocation methodSignature] numberOfArguments]);
	NSLog(@"Signature 2'sType %s",[[invocation methodSignature] getArgumentTypeAtIndex:2]);

}

-(void) timerControl:(NSString *)string
{
	NSLog(@"...");
}

@end