macOS/iOS API解説

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

目次

target

INDEX>Foundation>NSInvocation

起動オブジェクトのターゲットを返します

解説

起動オブジェクトのターゲットを返します。

返り値

( id )

ターゲットオブジェクト

引数

クラス

NSInvocation

Instance Methods

使用可能

10.0

参照

- setTarget

例文

#import "MyObject.h"
@implementation MyObject

NSTimer *timer=nil;

- (IBAction)myAction:(id)sender
{
	//メソッドシグネチャ
	NSMethodSignature *aSignature ;
    
	//起動オブジェクト
	NSInvocation *invocation ;
	
	//セレクタ
    SEL aSelector ;
    
	//セレクタをセット
	aSelector  = @selector( timerControl );
    
	//メソッドシグネチャをセット
	aSignature = [ self methodSignatureForSelector:aSelector ];
    
	//起動オブジェクトをセット
	invocation = [ NSInvocation invocationWithMethodSignature:aSignature ];
    
	//ターゲットはself
	[ invocation setTarget: self ];
    
	//セレクタをセット
	[ invocation setSelector: aSelector ];
    
	//ターゲット
    NSLog([[invocation target] className]);

    //タイマーで呼び出し                    
	timer = [NSTimer scheduledTimerWithTimeInterval:1
							invocation:invocation
								repeats:YES];

}

-(void) timerControl{
	NSLog(@"...");
}

@end