ios警告:Category is implementing a method which will also be implemented by its primary class 引發的相關處理


今天在處理項目中相關警告的時候發現了很多問題,包括各種第三方庫中的警告,以及各種亂七八糟的問題  先說說標題中的問題  Category is implementing a method which will also be implemented by its primary class  這個警告的意思是 我在category中重寫了原類的方法 而蘋果的官方文檔中明確表示  我們不應該在category中復寫原類的方法,如果要重寫 請使用繼承  原文是這樣的:A category allows you to add new methods to an existing class. If you want to reimplement a method that already exists in the class, you typically create a subclass instead of a category.  所以這里就出現了警告,警告而已,畢竟不是錯誤,所以也不會影響我們的使用,但是會讓人看着很不爽,所以查了一下不顯示這個警告的方法

1.在相關位置插入下面這段代碼

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"

// your override

#pragma clang diagnostic pop

2.在target的 build settings下  搜索other warning flags  然后給其添加 -Wno-objc-protocol-method-implementation

好了  警告沒有了

這里順便說一下  2中的方法  對很多批量的警告很有用  而后面相關字段 -Wno-objc-protocol-method-implementation  其實是可以查得到的    方法是在xcode中選擇你想屏蔽的警告,右鍵選擇 reveal in log 就可以在警告詳情中發現 -Wobjc-protocol-method-implementation  這么一個格式的字段 在-W后添加一個no-  然后在用2中的方法添加到 other warning flags 中 就可以處理大部分的警告了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM