How to get a unique identifier for a protocol object

I am trying to make a dictionary store a map of delegates that match the protocol. I need some consistent key representing the protocol.

For example, the following gives me a protocol object

Protocol * one = @protocol(SomeProtocolDefinedEarlier); 

And it responds to [one hash] , but the hash is not the same every time you get a protocol object for the same protocol. Is there a name message or something that I can use to identify it?

+4
source share
1 answer

Well, the protocols must have unique names (otherwise they will contradict each other), but what about:

 Protocol * aProtocol = ... NSString * protocolIdentifier = NSStringFromProtocol(aProtocol); 
+4
source

Source: https://habr.com/ru/post/1300669/


All Articles