Loose-Info.com
Last Update 2013/02/13
TOP - Objective-C - @selector

指定されたメソッドのコンパイルされたセレクタを返します。

@selector( 名前1 )

名前1
コンパイルされたセレクタを獲得する対象となるメソッド名

(例)
※ Xcodeで生成される「***_Prefix.pch」などのファイルの内容は記載しません。

#import <Foundation/Foundation.h> @interface MyTestClass1 : NSObject - (void)test_sel; @end @implementation MyTestClass1 - (void)test_sel { NSLog(@"MyTestClass1 → + (void)test_sel"); } @end @interface MyTestClass2 : MyTestClass1 @end @implementation MyTestClass2 @end int main (void) { MyTestClass1 *c11 = [[MyTestClass1 alloc] init]; MyTestClass1 *c12 = [[MyTestClass1 alloc] init]; MyTestClass2 *c21 = [[MyTestClass2 alloc] init]; SEL testSEL = @selector(test_sel); [c11 performSelector:testSEL]; [c12 performSelector:testSEL]; [c21 performSelector:testSEL]; return 0; }

実行結果
MyTestClass1 → + (void)test_sel MyTestClass1 → + (void)test_sel MyTestClass1 → + (void)test_sel