I have read in the Apple Documentation that we can use optional parameters in objective c methods call. Example from the Apple documentation :
Methods that take a variable number of parameters are also possible,
though they’re somewhat rare. Extra parameters are separated by commas
after the end of the method name. (Unlike colons, the commas are not
considered part of the name.) In the following example, the imaginary
makeGroup: method is passed one required parameter (group) and three
parameters that are optional:
[receiver makeGroup:group, memberOne, memberTwo, memberThree];
Can someone tell when to use this feature and how ? is there any example in the Apple API ?
thanks
The type of method you are describing is called a variadic method. Examples in Cocoa include
+[NSArray arrayWithObjects:]and+[NSDictionary dictionaryWithObjectsAndKeys:]. You access the arguments of a variadic method (or function) using the macros defined instdarg.h.Here’s an example of how the
+[NSArray arrayWithObjects:]method might be implemented: