Pass a protocol as a method argument
Protocol is a class, so you just write - (void)someMethod:(Protocol *)someArgument
like with any other object type. You can see this in the declaration for conformsToProtocol:
:
+ (BOOL)conformsToProtocol:(Protocol *)aProtocol
I don't recommend using protocol. It will obscure which interface your code actually relies on. Use id<yourprotocol>*
. This is actually how the cocoa frameworks pass protocols. Forgive the use of words if I don't it thinks I'm trying to do HTML.
If you know the name of a protocol at coding-time, use @protocol(SomeProtocol)
to get a pointer to that protocol, similar to how you'd use @selector(x)
.
Beyond that, you just refer to protocols with the class identifier Protocol
-- so you're method declaration would look like:
-(void)someMethod:(Protocol*)someArgument
You can see an example in the docs for NSObject conformsToProtocol:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#//apple_ref/occ/clm/NSObject/conformsToProtocol: