Objective-C respondsToSelector

前端 未结 4 1300
难免孤独
难免孤独 2020-12-04 06:07

From what I have learned so far: In Objective-C you can send any message to any object. If the object does implement the right method it will be executed otherwise nothing w

4条回答
  •  天涯浪人
    2020-12-04 06:35

    "This is because before the message is sent Objective-C will perform respondsToSelector."

    I guess this is not correct. If the object does not respond to selector, it will crash at runtime. There is no automatic checking by the system. If there was a check by the run time system then we should never get "unrecognized selector sent to instance" exception.

    Please make me correct if I am wrong.

    EDIT: This is not a straight forward crash, but the default result is the process will be terminated. The whole sequence is already explained in comment and other answer, so I am not going to write that again.

提交回复
热议问题