First parameter name in objective c? First parameter name in objective c? objective-c objective-c

First parameter name in objective c?


The normal way to do what you're asking is to declare your method like:

-(void)panLatitude:(double)lat longitude:(double)lon;

That is, include the label for the first argument with the method name at the beginning. You'd use it like:

[self panLatitude:x longitude:y];


You just need to name the method differently.

- (void)panToLatitude: (double)lat longitude: (double)lon;

Objective-C doesn't actually have named parameters. The name of the method is (in your example, not my version above) -pan:longitude: and the language uses infix notation to pass the arguments.


Remember that objective-c is about sending messages to objects - the message is the args. So the first part of the message often contains the verb and first piece of data. It should read easily.

Do not think of the method name as "pan". In C# and Java the method name would be Pan and the args would be longitude and latitude. Your method should be something like.

- (void) panToLatitude:longitude:

That string is your function (message) name. Think of it as send a message that is a dictionary and the first item contains the verb. I come from C langs background as well so it's a different way of thinking.