First let me explain what I don’t mean. I don’t want to type an argument to a protocol:
-(void)someMethod:(id<SomeProtocol>)someArgument;
What I do want to is to pass a protocol to a method in the same way I can pass a Class to a method (The following is incorrect, but it hopefully explains what I want to do):
-(void)someMethod:(Protocol)someArgument;
I would then like to be able to use the Protocol to check whether a set of objects implement it.
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: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: