Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>SEL is a type that represents a selector in Objective-C. The @selector() keyword returns a SEL that you describe. It's not a function pointer and you can't pass it any objects or references of any kind. For each variable in the selector (method), you have to represent that in the call to @selector. For example:</p> <pre><code>-(void)methodWithNoParameters; SEL noParameterSelector = @selector(methodWithNoParameters); -(void)methodWithOneParameter:(id)parameter; SEL oneParameterSelector = @selector(methodWithOneParameter:); // notice the colon here -(void)methodWIthTwoParameters:(id)parameterOne and:(id)parameterTwo; SEL twoParameterSelector = @selector(methodWithTwoParameters:and:); // notice the parameter names are omitted </code></pre> <p>Selectors are generally passed to delegate methods and to callbacks to specify which method should be called on a specific object during a callback. For instance, when you create a timer, the callback method is specifically defined as:</p> <pre><code>-(void)someMethod:(NSTimer*)timer; </code></pre> <p>So when you schedule the timer you would use @selector to specify which method on your object will actually be responsible for the callback:</p> <pre><code>@implementation MyObject -(void)myTimerCallback:(NSTimer*)timer { // do some computations if( timerShouldEnd ) { [timer invalidate]; } } @end // ... int main(int argc, const char **argv) { // do setup stuff MyObject* obj = [[MyObject alloc] init]; SEL mySelector = @selector(myTimerCallback:); [NSTimer scheduledTimerWithTimeInterval:30.0 target:obj selector:mySelector userInfo:nil repeats:YES]; // do some tear-down return 0; } </code></pre> <p>In this case you are specifying that the object obj be messaged with myTimerCallback every 30 seconds. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload