Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a method/message with multiple parameters?

How do you write a method/message with multiple parameters?

EDIT: Like multiple parameters for a single method/message, I mean.

like image 736
Devoted Avatar asked Jul 01 '09 00:07

Devoted


People also ask

How do you pass multiple parameters in a method?

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.

How can you pass multiple arguments to a method on each invocation call?

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.

How many parameters can a function have?

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.


1 Answers

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.

like image 97
Jeff Hellman Avatar answered Oct 29 '22 13:10

Jeff Hellman