[IOS]clang diagnostic、Wprotocol ..

來源:互聯網
上載者:User

[IOS]clang diagnostic、Wprotocol ..

首先, #pragma 本質上也是聲明,一般常用的功能就是打注釋、尤其是分段注釋

但是#pragma 另外一個強大的功能就是處理編譯器警告,用的時候可能就沒上一個

功能用的那麼多,在代碼中處理警告卻是極其高效的方法。

其中 clang diagnostic 便是#pragma 第一個功能常用的命令,步驟如下

#pragma clang diagnostic push#pragma clang diagnostic ignored "-相關命令"    // 你自己的代碼#pragma clang diagnostic pop

常見用法

1.方法棄用警示

    #pragma clang diagnostic push            #pragma clang diagnostic ignored "-Wdeprecated-declarations"           [TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]];            #pragma clang diagnostic pop   

2.不相容指標類型

    #pragma clang diagnostic push       #pragma clang diagnostic ignored "-Wincompatible-pointer-types"       //      #pragma clang diagnostic pop  

3.循環參考

    // 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"     int a;   #pragma clang diagnostic pop  


#pargma 用法詳情:

http://nshipster.cn/pragma/

http://nshipster.com/clang-diagnostics/

相關的命令列表

http://fuckingclangwarnings.com/


進階:

http://clang.llvm.org/docs/UsersManual.html#diagnostics_pragmas



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.