can I get the list of messages that one object can response in runtime? (in Cocoa).
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
@Wooble’s answer is correct. An object can choose to respond to a message or not, and you can even add/remove/swap methods at runtime.
If you want to get a list of methods that an object currently implements (note: this is different than what messages an object will respond to), you can do so like this:
This is pretty neat, but be aware that this will only give you the instance methods implemented by the class. In other words, it will not give you the methods inherited from a superclass. To get those methods, you must inspect the superclass directly.
If you want to get all of the class methods implemented by a specific class, then you replace:
with: