‘xxx’ used as the name of the previous parameter rather than as part of the selector

在使用XCode编写代码的时候声明一个方法,如果出现“‘xxx’ used as the name of the previous parameter rather than as part of the selector”警告,这个警告虽然不会影响程序的运行,但是在阅读代码和编译时,总会出现一个黄色的按钮,总是让人看着不那么舒服。
例如:- (NSString *)setString:(NSString *)string1:(NSString *)string2 。声明这个方法后就会出现警告,这样的警告通常是由声明方法而不对制定参数进行描述引起的--第一个参数和冒号之间没有参数描述或者空格。当然,如果按照正常的编程习惯,这种警告是不会出现的。但是在进行快速迭代的开发过程中,在时间紧迫的情况下,不排除这样的情况出现的可能(粗心大意或者省懒事儿)。
接下来就是解决办法:
1、用空格隔开:- (NSString *)setString:(NSString *)string1 :(NSString *)string2
(按照正常的编程习惯不推荐,阅读性太差/(ㄒoㄒ)/~~)
2、增加参数描述
- (NSString *)setString:(NSString *)string1 String:(NSString *)string2
(强烈建议这样声明)
3、在相关位置添加
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-selector-name"
// 在这声明方法
#pragma clang diagnostic pop
4、在target的 build settings下 搜索other warning flags 添加:
-Wmissing-selector-name
方法4可以解决整个项目中的这样的问题,还可以用这样的办法去掉其他警告,只需替换掉添加的字符串。

虽然警告对程序运行没有影响,但是记得有位老师说过,警告就是错误。所以说编程时一定要细心,遵循正确的编程语言语法和习惯。

你可能感兴趣的:(‘xxx’ used as the name of the previous parameter rather than as part of the selector)