What is the difference between instancesRespondToSelector and respondsToSelector in Objective-C?

后端 未结 3 814
轻奢々
轻奢々 2020-12-30 04:42

The only difference I observed on my own is that respondsToSelector\'s receiver can either be a class or an instance, while instancesRespondToSelector

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 05:16

    respondsToSelector: is an instance method and determines whether an object, which could be an instance of a class or a class object, responds to a selector. When you pass a instance you are testing for an instance method, when you pass a class object you are testing for a class method.

    instancesRespondToSelector: is a class method and determines if instances of a class respond to a selector. It allows testing for an instance method given a class and without having an instance of that class.

提交回复
热议问题