Objective-C Make a choice when to use a colon?

You only postfix the method name with: if you are calling a foreign object?

For some reason

[self performSelector:@selector(myMethod:) withObject:nil afterDelay:5]; 

Not working but

 [self performSelector:@selector(myMethod) withObject:nil afterDelay:5]; 

whether!

EDIT:

Declared in the implementation of the class, but not the interface.

 - (void)myMethod { // Some stuff } 
0
source share
2 answers

The colon represents the argument of the method. Since myMethod takes no arguments, the selector cannot have a colon. If you had several arguments like this ...

 - (void)myMethod:(id)method object:(id)object enabled:(BOOL)bool { // Some Stuff } 

... the selector will be @selector (myMethod: object: enabled :)

+9
source

In Objective-C, colons are part of the method name. That is, myMethod and myMethod: are clear selectors (and in your case only the latter exists).

For example, for a method declared as:

 -(void)doSomethingWithFoo:(int)foo andBar:(int)bar; 

doSomethingWithFoo:andBar: selector.

+4
source

All Articles