开发者

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

开发者 https://www.devze.com 2023-01-14 01:45 出处:网络
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

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

精彩评论

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