最終更新:2012-09-25 (火) 02:09:43 (4203d)
@selector
Top / @selector
The @selector() directive lets you refer to the compiled selector, rather than to the full method name.
そのセレクタがコンパイル時に変換される内部表現(SEL)を、プログラム上で扱えるようにするコンパイラ指示子
SEL selector = @selector(メソッド名)
- 指定したメソッドの名前が存在するかどうかは、メソッドを呼び出すときに、実行時に判定されるため、コンパイル時には評価されない
メソッド名
- hoge - 引数なし
- hoge: - 引数1つ
- hoge:fuga: - 引数2つ
例
SEL setWidthHeight; setWidthHeight = @selector(setWidth:height:);
SEL
- コンパイル済みのセレクタ
typedef struct objc_selector *SEL;
- SELオブジェクトに格納したメソッドの実行にはNSObjectのperformSelectorを用いる。
- NSObject
- (id)performSelector:(SEL)aSelector - (id)performSelector:(SEL)aSelector withObject:(id)anObject - (id)performSelector:(SEL)aSelector withObject:(id)anObject withObject:(id)anotherObject