sangony
sangony

Reputation: 11696

Naming methods and passing values

Taking the below method as an example:

-(void)myMethodName:(int)xCoordinate yCoordinate:(int)yCoordinate

When I write the method in my code [self etc...], Xcode does its auto complete which tells me what the second value is for but never the first (see pic).

enter image description here

Is there any way I can also include the 'description' for the first value of a method?

Upvotes: 0

Views: 49

Answers (4)

Popeye
Popeye

Reputation: 12093

Based on the Apple Documentation on coding guidelines for cocoa when naming methods with parameters the word before the argument should describe the argument.

Make the word before the argument describe the argument.

Right - (id)viewWithTag:(NSInteger)aTag;

The above is right because it describes the argument as a Tag where as the below doesn't describe the argument as anything.

Wrong - (id)taggedView:(int)aTag;

So in your case

Wrong -(void)myMethodName:(int)xCoordinate yCoordinate:(int)yCoordinate;

it should be

Right -(void)myMethodNameForXCoordinates:(int)xCoordinate andYCoordinate:(int)yCoordinate;

Upvotes: 0

Sam B
Sam B

Reputation: 27608

This is how the methods are usually defined in objective C

- (int)addX:(int)x toY:(int)y {
      int sum = x + y;
      return sum;
  }

Like others have said rename your method this way and it will make things clearer

-(void)moveStuffFromXCoordinate:(int)xCoordinate toYCoordinate:(int)yCoordinate

Upvotes: 1

Chuck
Chuck

Reputation: 237060

This is just a matter of how you name your method. It autocompletes the entire method name. If the method name is descriptive of its parameters, then you'll see it in the autocomplete.

Upvotes: 2

Logan
Logan

Reputation: 53112

Are you trying to get something like this?

-(void)myMethodNameWithXCoordinate:(int)xCoordinate yCoordinate:(int)yCoordinate

Upvotes: 1

Related Questions