Search code examples
objective-cparametersmethodsmessage

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.


Solution

  • 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.