ento’s posterous

postit 
Filed under

objectivec

 

NSInvocation にはメソッドシグネチャとセレクタ名を両方教える

1 時間ほどはまったのでメモ:
 

 
- (id)setTarget:(id)target selector:(SEL)selector {
  NSMethodSignature * sig = nil;
  sig = [[target class] instanceMethodSignatureForSelector:selector];
  assert(strcmp([sig methodReturnType], @encode(CGPoint)) == 0);
 
  NSInvocation * myInvocation = nil;
  myInvocation = [NSInvocation invocationWithMethodSignature:sig];
  [myInvocation setTarget:target];
  [myInvocation setSelector:selector]; // !!!
 
  self.invocation = myInvocation;
  return self;
}

 
どんなメソッドの情報を渡してるからセレクタ名だって分かりそうなものだと思ったけど、Objective-Cではセレクタ名はメソッドシグネチャに含まれないらしい
[1]
 
[1] http://en.wikipedia.org/wiki/Method_signature

Loading mentions Retweet
Filed under  //   Objective-C  

Comments [0]