开发者

iPhone SDK @selector -> SEL @protocol ->?

okay so I want to make a public function that will return YES if an object exists, conforms to a protocol and responds to a selector. I know the typedef of @selector is SEL but what is the typedef for @protocol

BOOL conforms(id object, ? prototype, SEL action) {
  return (object != nil && 
         [object conformsToProtocol:prototype] && 
         [object respondsToSelector:action]);
}

And I want to be able to call this function like:

if(conforms(delegate, @protocol(U开发者_如何学运维IScrollViewDelegate), 
   @selector(touchesBegan:withEvent:))) {
  [delegate touchesBegan:touches withEvent:event];
}


You're looking for the Protocol object:

BOOL conforms(id object, Protocol *protocol, SEL action) {
  return (object != nil && 
         [object conformsToProtocol:protocol] && 
         [object respondsToSelector:action]);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜