首先, #pragma 本質(zhì)上也是聲明丰捷,一般常用的功能就是打注釋冯乘、尤其是分段注釋
但是#pragma 另外一個(gè)強(qiáng)大的功能就是處理編譯器警告,用的時(shí)候可能就沒(méi)上一個(gè)
功能用的那么多点弯,在代碼中處理警告卻是極其高效的方法嗤练。
其中 clang diagnostic 便是#pragma 第一個(gè)功能常用的命令榛了,步驟如下
#pragma clang diagnostic push
#pragma?clang?diagnostic?ignored?"-相關(guān)命令"
//?你自己的代碼
#pragma?clang?diagnostic?pop
常見(jiàn)用法
1.方法棄用告警
#pragma clang diagnostic push
#pragma?clang?diagnostic?ignored?"-Wdeprecated-declarations"
[TestFlightsetDeviceIdentifier:[[UIDevicecurrentDevice]uniqueIdentifier]];
#pragma?clang?diagnostic?pop
2.不兼容指針類(lèi)型
#pragma clang diagnostic push
#pragma?clang?diagnostic?ignored?"-Wincompatible-pointer-types"
//
#pragma?clang?diagnostic?pop
3.循環(huán)引用
// completionBlock is manually nilled out in AFURLConnectionOperation to break the retain cycle.
#pragma?clang?diagnostic?push
#pragma?clang?diagnostic?ignored?"-Warc-retain-cycles"
self.completionBlock=?^?{
...
};
#pragma?clang?diagnostic?pop
4.未使用變量
#pragma clang diagnostic push
#pragma?clang?diagnostic?ignored?"-Wunused-variable"
inta;
#pragma?clang?diagnostic?pop
#pargma 用法詳情:
http://nshipster.com/clang-diagnostics/
相關(guān)的命令列表
http://fuckingclangwarnings.com/
進(jìn)階:
http://clang.llvm.org/docs/UsersManual.html#diagnostics_pragmas