0

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

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
aneuryzm
  • 63,052
  • 100
  • 273
  • 488

2 Answers2

3

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

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
1
  1. Because CGRectMake() and CGRectGetHeight() are C functions, not Objective-C or Objective-J methods. Parameters are passed comma-separated in parentheses for C function calls.

    The result of CGRectMake() is then passed as a parameter to the initWithFrame: method of the CPView class, which is an Objective-C method.

  2. As for your second question I've not seen that method before so I can't really tell what the prefs parameter is used for...

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356