I can’t find this answer anywhere. What does it mean when there’s a sender parameter in a method header? Does it represent the instance that called it, or the method that called it?
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.
There’s no magic involved. You are probably talking about the methods linked to some user interface elements by Interface Builder, right?
The IBAction is a macro that expands to void. It’s simply a syntactic sugar that marks the methods you want to be available in the Interface Builder. Now when you connect this method to some interface element, say a button, IB calls the addTarget… method on the button:
And when you press the button, it goes through its list of actions and fires the userDidPressButton, passing itself as the first argument. This is probably not that much useful for buttons, but you can also use the same mechanism to get change events from a slider, and in that case you can use the sender argument to get the slider value.