Sean Clark Hess
Sean Clark Hess

Reputation: 16079

How to get a unique identifier for a protocol object

I'm trying to make a dictionary store a map of delegates that correspond to a protocol. I need some consistent key that represent a protocol.

For example the following gives me a protocol object

Protocol * one = @protocol(SomeProtocolDefinedEarlier);

And it responds to [one hash] but the hash isn't the same each time you get a protocol object for the same protocol. Is there some name message or something I can use to identify it?

Upvotes: 4

Views: 657

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243156

Well, protocols must have unique names (otherwise they'd conflict with each other), so how about:

Protocol * aProtocol = ...
NSString * protocolIdentifier = NSStringFromProtocol(aProtocol);

Upvotes: 4

Related Questions