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
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
- (NSString *) getFormattedDateString:(NSDate *)date :(NSString*)formatString;
2. Add a description forthe
- (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"