How do you write a method/message with multiple parameters?
EDIT: Like multiple parameters for a single method/message, I mean.
Note that when you are working with multiple parameters, the method call must have the same number of arguments as there are parameters, and the arguments must be passed in the same order.
The * symbol is used to pass a variable number of arguments to a function. Typically, this syntax is used to avoid the code failing when we don't know how many arguments will be sent to the function.
Except for functions with variable-length argument lists, the number of arguments in a function call must be the same as the number of parameters in the function definition. This number can be zero. The maximum number of arguments (and corresponding parameters) is 253 for a single function.
You can write the declaration as such:
- (void) drawRoundedRect:(NSRect)aRect inView:(NSView *)aView withColor:(NSColor *)color fill:(BOOL)fill
The subsequent call (with 4 parameters) could look like:
[self drawRoundedRect:rect inView:self withColor:[NSColor greenColor] fill:YES];
where rect
is a previously defined NSRect, self
is the NSView the method is called from, an NSColor
object obtained from a nested method call, and the constant boolean value YES
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With