Firdous
Firdous

Reputation: 4652

Add parameter in function signature in objective C

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.

Upvotes: 0

Views: 554

Answers (2)

CRD
CRD

Reputation: 53010

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; }

Upvotes: 1

jonkroll
jonkroll

Reputation: 15722

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.

Upvotes: 1

Related Questions