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]);
}
精彩评论