#pragma 本質(zhì)上就是聲明贞间,一般用來打注釋坝锰。但是它還有另外一個(gè)強(qiáng)大的功能婚脱,便是處理警告今魔。用法如下:
#pragma clang diagnostic push
#pragma clang diagnostic ignored “-相關(guān)的命令"
?//你自己的代碼
#pragma clang diagnostic pop
常見用法:
1.方法棄用警告
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
//自己的代碼
#pragma clang diagnostic pop
2.不兼容指針類型
#pragma clang diagnostic push
#pragma clang diagnostic ignored “-Wincompatible-pointer-types"
?//自己的代碼
#pragma clang diagnost
3.循環(huán)引用
#pragma clang diagnostic push
#pragma clang diagnostic ignored “-Warc-retain-cycles"
?//自己的代碼
#pragma clang diagnost
4.未使用的變量
#pragma clang diagnostic push
#pragma clang diagnostic ignored “-Wunsed-variable"
?//自己的代碼
#pragma clang diagnost
5 .分類重寫主類方法
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"? ? ? ? ?
?//自己的代碼
#pragma clang diagnost
6.未使用default
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcovered-switch-default"? ? ? ?
?//自己的代碼
#pragma clang diagnost
7.內(nèi)存泄漏
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
?//自己的代碼
#pragma clang diagnost