views:

70

answers:

2

I just spotted the following in an online tutorial. It showed 001 as a method for assigning a selector, however I could not get this to work. Am I right in thinking that 001 is not right and 002 is the correct way, or am I doing something wrong with 001?

// 001
SEL mySel = [self something];

// 002  
SEL mySel = @selector(something);

.

-(void)something {
    NSLog(@"YAY");
}

Gary

+1  A: 

001 is the syntax for calling something (sending something to self).
002 is correct for assigning to a SEL object.

Seems like an error in that tutorial to me.

progrmr
+6  A: 

It's not necessarily an error. As pointed out, 001 is the syntax for calling a method. That said, methods can return a selector just fine, so 001 is valid only if -something on self returns a SEL.

Your definition of -something though doesn't, so in this respect 001 is an error in the tutorial if that's how they defined -something.

jer
So for example: `-(SEL) something { return @selector(somethingElse:) ; }` would be a valid method in 001.
JeremyP
Hi Jer / JeremyP, perfect, the error is mine I was miss understanding and thinking that SEL was a pointer to the method. I now understand that the first example needs a method that returns a SEL.
fuzzygoat