Are selectors in Objective-C just another way to send a message to an object? I really don’t understand why or how to use them.
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.
They aren’t another way to send a message to an object, they’re the only way. For example, in
[myView setValue:@"foo"],setValue:is a selector. (Another, less convenient way of writing the same thing isobjc_msgSend(myView, @selector(setValue:), @"foo").)As Ian Henry says, you can use
SELvalues to choose a selector at runtime instead of compile time. This is a fundamental technique in Cocoa; user interfaces are generally connected to controllers using target/action bindings, where the target is an object and the action is a selector. Normally you set this up in a nib, but you can also do it in code: