使用pragma消除警告 (绝不可强行消除,因为有可能是个运行时错误)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "命令字符串"
代码块
#pragma clang diagnostic pop
1. "-Warc-performSelector-leaks" performselector可能造成内存泄漏
SEL sel = @selector(gl_getImage:);
[self performSelector:sel withObject:nil];
以上警告也可使用消除
IMP imp = [app methodForSelector:sel];
void (*func)(id , SEL ,NSInteger) = (void *)imp;
func(app,selector,0);
2. "-Wreceiver-is-weak" 调用者接收者是weak属性
3. "-Wunused-variable" 变量未使用
或者 __unused int m = 2; //Unused variable 'm'
4. "-Wdeprecated-declarations" 方法弃用
[UIAlertView alertView........]
5. "-Warc-retain-cycles" 循环引用
while(true){}
6. "-Wincompatible-pointer-types" 指针不兼容的
7. "-Wundeclared-selector" 方法在本类中未申明
eg. SEL sel = @selector(gl_getImage)
不过以上方法导致的警告也可使用runtime机制消除
SEL sel = sel_registerName("gl_getImage:")
SEL sel = NSSelectorFromString(@"gl_getImage:");
8. "-Wunreachable-code" 代码将永不被执行
NSLog(@"m");
return;
NSLog(@"n"); //Code will never be executed
如果想将项目中所有某类型的警告都消除
11. 配置文件 buildSettings->Other Warning Flags
加入配置字符
11.1 code will never be executed
-Wno-unreachable-code 全局禁用警告
-Wunreachable-code 全局启用警告
11.2 Unused Entity Issue / unused function 'xxxxx'
-Wno-unused-function 全局禁用
-Wunused-function 全局启用
11.3 ......