Search code examples
objective-csyntaxcappuccinoobjective-j

I've some hard time to understand method signatures in Objective-J / Objective-C


I've some hard time to understand method signatures in Objective-J (but it should be the same on Objective-C).

The syntax should be:

-(return_type)instanceMethod1:(param1_type)param1_varName :(param2_type)param2_varName;

The type is specified between parenthesis. However, I've found the following code line:

1)

var navigationArea = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 150.0, CGRectGetHeight([contentView bounds]) - 150.0)];

Why are the parameters passed in between parenthesis ? I thought you specify parameters after a colon ":".

2)

-(void) importDocumentWithName:(NSString *)name withSpecifiedPreferences:(Preferences *)prefs beforePage:(int)insertPage;

what's "withSpecifiedPreferences" ? Is it the description ? What's the use of it ?

thanks


Solution

  • 1) shows a mix of two styles, the Objective-C style method calls:

    [[CPView alloc] initWithFrame:...];
    

    and C-style function calls:

    CGRectMake(1, 2, 3, 4);
    

    Objective-J is a strict super-set of JavaScript, which means that you can use the message-passing syntax in addition to the C-style function call syntax JavaScript has.

    In 2), withSpecifiedPreferences: is part of the methods (or "selectors") name, see "Message Syntax".