In Objective-C, what does “(UIButton *)sender” mean and why is it not “UIButton *sender”? Or some NSObject in place of UIButton. This is more a question about the precedence of the asterisk…
- (IBAction)digitPressed:(UIButton *)sender {
//...
}
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.
It’s not about precedence in this case. The parentheses aren’t a cast.
This is the syntax in ObjC for a method declaration, and it says that the parameter called
senderis of typeUIButton *.The asterisk goes with the UIButton because they together name the type of the argument. In this case, since it’s an action method coming from a button, you’re using a UIButton*. In the general case, of course, a method may have parameters of any type, as long as the caller is calling it correctly. 🙂