Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use colon : or not with selectors

I was wondering: what's the difference between writing a selector name with no colon @selector(mySelector), or @selector(mySelector:) with the colon?

As in:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWith... 
                                                       target:self
                                                       action:@selector(addAction:)];

I can't find another example without the colon, but I'm quite sure I have already seen some of them.

like image 399
Paul Avatar asked Sep 05 '11 16:09

Paul


People also ask

Can I use a colon in a CSS class?

A CSS pseudo-element is a keyword added to a CSS selector that lets you style a specific part of the selected HTML element. In CSS3, they are usually denoted by two colons — for example, ::first-line — to differentiate them from pseudo-classes. In contrast, CSS2 syntax uses one colon (e.g., :first-line ).

Is it before or :: Before CSS?

Technically, the correct answer is ::before .

What is the use of colon in jQuery?

jQuery can use some of these to perform selections as well. One of these is :even which selects every other matched element starting with the second. Basically, it's being used here as a shortcut for selecting half of the pieces.

Which features uses double colon?

It means pseudo element selector. It means the element to the right doesn't exist in the normal DOM, but can be selected.


1 Answers

The colon is needed after the method's name if and only if the method takes an argument.

No function parameters:

-(void)addAction {}

// Use ...@selector(addAction)...

Has parameter:

-(void)addAction:(id)info {}

// Use ...@selector(addAction:)...
like image 148
Evan Mulawski Avatar answered Oct 20 '22 01:10

Evan Mulawski