0

What should I do the the function signature below to add one more parameter:

- (void)locationPondSizeViewController: (LocationPondSizeViewController *)controller didSelectPondSize:(NSString *)thePondSize { .... } 

its actually a delegate function and called from:

[self.delegate locationPondSizeViewController:self didSelectPondSize:thePondSize]; 

Also help me to understand what is delegate name, function name, parameters, and return type in this signature.

1
  • 1
    Just append parameter1:(id)parameter1 parameter2:(id)parameter2 to the method name? Commented Feb 23, 2012 at 6:35

2 Answers 2

1

This sounds a bit like a homework question...

The Objective-C declaration:

- (void)locationPondSizeViewController:(LocationPondSizeViewController *)controller didSelectPondSize:(NSString *)thePondSize { ... } 

would be written in a language using more traditional style declarations as:

void locationPondSizeViewController:didSelectPondSize:(LocationPondSizeViewController *controller, NSString *thePondSize) { ... } 

(though most languages don't allow :'s in an identifier)

So the method/function name is locationPondSizeViewController:didSelectPondSize:, it takes two parameters of types LocationPondSizeViewController * and NSString * and returns nothing (void), i.e. its a procedure. The parameters are referred to in it's body as controller and thePondSize.

You extend for further parameters by adding " <part of name>:(<type>)<parameter name>" as many times as you need.

Pointless tidbit: You actually do not need to precede the colons with anything, this is a valid definition of the method :::

- (int) :(int)x :(int)y { return x + y; } 
Sign up to request clarification or add additional context in comments.

Comments

1

Here's an example of your method with an additional parameter added:

- (void)locationPondSizeViewController:(LocationPondSizeViewController *)controller didSelectPondSize:(NSString *)thePondSize withNewParameter:(NSObject*)newParam { ... } 

And here's how you would call it:

[self.delegate locationPondSizeViewController:self didSelectPondSize:thePondSize withNewParameter:myParam]; 

In this example the method signature is - locationPondSizeViewController:didSelectPondSize:withNewParameter:

It takes three parameters: 1) controller, 2) thePondSize, and 3) newParam

The return type of this method is void.

1 Comment

This is perfect. Firdous, notice that he's not putting a return after locationPondSizeViewController: and before (LocationPondSizeViewController *)controller, which makes it hard to read. If you'd rather, you can also put the entire method signature on one line with a space between each part.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.