I have found a strange as for me way to declare a method in Objective C.
Method declaration in .h file:
-(void)methodName:(NSString *)str, int i;
Method implementation in .m file:
-(void)methodName:(NSString *)str, int i
{
NSLog(@"str = %@, int = %d", str, i);
}
I can call this method like this:
[self methodName:@"stringExample", 99];
And it would work fine.
My question is when should I use such syntax. Is there any difference between it and usual declaration?
As described here, those parameters are optional:
So yes, the declaration is different to the usual declaration. I cannot find any regular use of this type of declaration other than with a varargs method, where the optional parameter is declared as
....