There are some functions which take as an argument @selector(methodName). I used NSLog to find out what @selector is, and it returns an integer. It looks like a PID, but when I ran ps ax that PID could not be found. What does that integer represent and why do we have to use @selector all the time instead of just passing the method name?
A selector is one of the properties of the object that we use along with the component configuration. A selector is used to identify each component uniquely into the component tree, and it also defines how the current component is represented in the HTML DOM.
Meaning of selector in Englisha person who chooses a sports team: His performance persuaded the selectors that he should be included in the team. Machines - general words. 3-D printer.
A CSS selector selects the HTML element(s) for styling purpose. CSS selectors select HTML elements according to its id, class, type, attribute etc. There are many basic different types of selectors. HTML code: Consider the sample code to understand selectors and their uses in a better way.
@selector()
is a compiler directive to turn whatever's inside the parenthesis into a SEL
. A SEL
is a type to indicate a method name, but not the method implementation. (For that you'd need a different type, probably an IMP
or a Method
) Under-the-hood, a SEL
is implemented as a char*
, although relying on that behavior is not a good idea. If you want to inspect what SEL
you have, the best way to do it is to turn it into an NSString*
like this:
NSLog(@"the current method is: %@", NSStringFromSelector(_cmd));
(Assuming you know that _cmd
is one of the hidden parameters of every method call, and is the SEL
that corresponds to the current method)
The Objective-C Programming Language Guide has much more information on the subject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With