开发者

Assigning a selector via SEL type?

I just spotted the following in an online tutorial. It showed 0开发者_开发百科01 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜