Jul*_*les 31 iphone xcode cocoa-touch objective-c
我从Xcode 4.6收到以下警告.
.. used as the name of the previous parameter rather than as part of the selector
Run Code Online (Sandbox Code Playgroud)
我知道我可以禁用此警告,但我宁愿修复它.
我有109个这样的警告,所以我显然写的方法很糟糕.
这是我的几个方法.
+(NSString*)addFormatPrice:(double)dblPrice:(BOOL)booRemoveCurSymbol;
-(void)showHelpChoices:(UIView *)vw:(id)dg;
Run Code Online (Sandbox Code Playgroud)
那么,编写这些方法的正确方法是什么?
Lil*_*ard 78
您的第一种方法是声明选择器+addFormatPrice::
.有空格,看起来像
+ (NSString *)addFormatPrice:(double)dblPrice :(BOOL)booRemoveCurSymbol;
Run Code Online (Sandbox Code Playgroud)
这被调用了[NSString addFormatPrice:0.3 :YES]
.
你应该做的是给上一个参数命名,例如
+ (NSString *)addFormatPrice:(double)dblPrice removeCurSymbol:(BOOL)booRemoveCurSymbol;
Run Code Online (Sandbox Code Playgroud)
然后会调用它[NSString addFormatPrice:0.3 removeCurSymbol:YES]
.
Jos*_*ell 12
也许你会更容易理解你是否将它们分成几行?
+(NSString*)addFormatPrice:(double)dblPrice
:(BOOL)booRemoveCurSymbol;
-(void)showHelpChoices:(UIView *)vw
:(id)dg;
Run Code Online (Sandbox Code Playgroud)
Objective-C方法名称的结构如下:
- (returntype)firstPartOfMethodWithParameter:(type)nameOfFirstParameter secondPartOfNameWhichDescribesSecondParameter:(type)nameOfSecondParameter;
Run Code Online (Sandbox Code Playgroud)
也就是说,完整的方法名称被拆分,参数名称散布在一起.冒号将每个"标签"与其参数分开; 空格将参数名称与方法名称的下一部分分开.
您的方法缺少第二部分,即描述第二个参数的位.现在,你的方法的名称是addFormatPrice::
和showHelpChoices::
,都是合法的,但不是惯用的.当你打电话给他们时,它看起来像这样:
[Excelsior addFormatPrice:2.0 :YES];
[thumpy showHelpChoices:aView :obj];
Run Code Online (Sandbox Code Playgroud)
这应该清楚表明你的名字不太正确.您只需要为第二个参数添加标签:
+(NSString*)addFormatPrice:(double)dblPrice
removingCurrencySymbol:(BOOL)booRemoveCurSymbol;
-(void)showHelpChoices:(UIView *)vw
digeridoo:(id)dg;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
27534 次 |
最近记录: |