iphone - tutorial - cocoa touch vs uikit

Xcode 4.6, used as the name of the previous parameter rather than as part of the selector (3)

I'm getting the following warning from Xcode 4.6.

.. used as the name of the previous parameter rather than as part of the selector

I know I can disable this warning, but I'd rather fix it.

I have 109 such warnings, so I'm obviously writing methods badly.

Here's a couple of my methods.


-(void)showHelpChoices:(UIView *)vw:(id)dg;

So, whats the correct way to write these methods ?

For advice on naming Objective-C methods, you should turn to an Objective-C style guide such as Apple's coding guidelines for Cocoa. Any style guide that follows the conventions of the community and Apple's frameworks will suggest that you name your method such that the purpose of each parameter is clearly described within the method name.

+(NSString *)priceStringWithPrice:(double)price removeCurrencySymbol:(BOOL)removeCurrencySymbol

-(void)showHelpChoicesInView:(UIView *)view withSomethingWithAnUndecipherableName:(id)mysteryParameter

Notice the significant change in name to indicate what (I assume) it does in your program and what each parameter does. Your class method doesn't add anything to anything - rather it returns a new string. This makes your code blend naturally with that of other developers, Apple's frameworks, other libraries you may use, and enhances the readability greatly. Not naming your parameters degrades readability and makes maintainability far more difficult.

On a related note, unnecessary abbreviations, including Hungarian notation, are jarring and don't fit the style, and if you follow good naming practices you don't need them and will produce code that is a pleasure to maintain. So don't call it vw, call it view or viewToShowIn. Don't call it strVal call it valueString or somethingSpecificallyDescribingTheNatureOfTheValueString.

Maybe you'll have an easier time understanding if you split these across several lines?


-(void)showHelpChoices:(UIView *)vw

An Objective-C method name's structure is like this:

- (returntype)firstPartOfMethodWithParameter:(type)nameOfFirstParameter secondPartOfNameWhichDescribesSecondParameter:(type)nameOfSecondParameter;

That is, the full method name is broken up, with the parameter names interspersed. The colons separate each "label" from its parameter; a space separates the parameter name from the next part of the method name.

Your methods are missing the second parts, the bits that describe the second parameters. Right now, the names of your methods are addFormatPrice:: and showHelpChoices::, both of which are legal but un-idiomatic. When you call them, it will look like this:

[Excelsior addFormatPrice:2.0 :YES];
[thumpy showHelpChoices:aView :obj];

which should make it clear that your names aren't quite right. You just need to add the labels for the second parameters:


-(void)showHelpChoices:(UIView *)vw

Your first method is declaring the selector +addFormatPrice::. With spaces, it looks like

+ (NSString *)addFormatPrice:(double)dblPrice :(BOOL)booRemoveCurSymbol;

This is invoked like [NSString addFormatPrice:0.3 :YES].

What you should do is actually give a name to the previous parameter, such as

+ (NSString *)addFormatPrice:(double)dblPrice removeCurSymbol:(BOOL)booRemoveCurSymbol;

Which would then be invoked like [NSString addFormatPrice:0.3 removeCurSymbol:YES].