iosobjective-c-protocol

When should I use conformsToProtocol and respondsToSelector methods?


What is the use of conformsToProtocol and respondsToSelector method?


Solution

  • conformsToProtocol method let you check is your object implement specific protocol. It doesn't tell you has it contains the method this protocol defines (some of the method can be optional).

    respondsToSelector check is your object has a specific method (the method doesn't need to be defined in any protocol) it can be method defined in class.