:问题的核心在于:没有按照Ob-C推荐的方法来声明多参数函数。省略了第二个或是后面参数的参数名,只用到一个冒号和行参名称,这样就造成编译器(Xcode 4.6及以上)警告。下文一共提供了三种方法来解决这一问题。
When you upgrade to Xcode 4.6, you may find that you are getting a number of compiler warnings like this:
‘xxxxx’ used as the name of the previous parameter rather than as part of the selector
In this post I will show you why you’re getting this warning, how to fix it, or how to ignore it.
Why You’re Getting This Warning
This is typically caused by declaring a method without specifying a description of the parameter. For example, check out the following method declaration:
– (NSString *) getFormattedDateString:(NSDate *)date:(NSString *)formatString;
The intent of this code is to declare a method named getFormattedDateString that accepts two parameters named date and formatString.
Because there is no space between date and the colon (:), the compiler gives the warning “‘date’ used as the name of the previous parameter rather than as part of the selector”.
How to Fix The Problem
There are two ways to solve this warning:
1. Put a space between date and the colon:
– (NSString *) getFormattedDateString:(NSDate *)date :(NSString *)formatString;
2. Add a description for the formatString parameter:
– (NSString *) getFormattedDateString:(NSDate *)date withFormat:(NSString *)formatString;
The second option is preferable because it makes your method more readable. That;s because parameter descriptions are part of the method signature. In this example, the method signature is:
getFormattedDateString:withFormat:
If you leave out the parameter description, the method signature is the less readable:
getFormattedDateString::
How to Ignore the Warning
Although it’s preferable to fix these warnings by changing your method declarations, if you want to ignore them, you can simply add the following declaration to your project’s PCH file (located in the Support Files group):
#pragma clang diagnostic ignored “-Wmissing-selector-name”