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

时间:2010-09-03 02:00:05

标签: iphone protocols selector

好吧所以我想创建一个公共函数,如果对象存在,将返回YES,符合协议并响应选择器。我知道@selector的typedef是SEL,但是@protocol

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

我希望能够像以下一样调用此函数:

if(conforms(delegate, @protocol(UIScrollViewDelegate), 
   @selector(touchesBegan:withEvent:))) {
  [delegate touchesBegan:touches withEvent:event];
}

1 个答案:

答案 0 :(得分:4)

您正在寻找Protocol对象:

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