How To Fix Xcode's "used as the name of&

When you upgrade to Xcode 4.6, you may find that you are getting anumber of compiler warnings like this:

'xxxxx' used as the name of the previous parameter ratherthan as part of the selector

In this post I will show you why you're getting this warning, howto fix it, or how to ignore it.

Why You're Getting This Warning

This is typically caused by declaring a method without specifying adescription of the parameter. For example, check out the followingmethod declaration:

- (NSString *) getFormattedDateString:(NSDate *)date:(NSString*)formatString;

The intent of this code is to declare a methodnamed getFormattedDateString thataccepts two parametersnamed date and formatString.

Because there is no space between date and the colon (:), thecompiler gives the warning "'date' used as the name of the previousparameter rather than as part of the selector".

How to Fix The Problem

There are two ways to solve this warning:

1. Put a spacebetween date andthe colon:在date变量和冒号间加个空格

- (NSString *) getFormattedDateString:(NSDate *)date :(NSString*)formatString;

2. Add a description forthe formatString parameter:为fotmatString参数加个描述

- (NSString *) getFormattedDateString:(NSDate *)datewithFormat:(NSString *)formatString;

The second option is preferable because it makes your method morereadable. That;s because parameter descriptions are part of themethod signature. In this example, the method signature is:

getFormattedDateString:withFormat:

If you leave out the parameter description, the method signature isthe less readable:

getFormattedDateString::

How to Ignore the Warning

Although it's preferable to fix these warnings by changing yourmethod declarations, if you want to ignore them, you can simply addthe following declaration to your project's PCH file (located inthe Support Files group):

#pragma clang diagnostic ignored "-Wmissing-selector-name"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值