標籤:
今天在處理項目中相關警告的時候發現了很多問題,包括各種第三方庫中的警告,以及各種亂七八糟的問題 先說說標題中的問題 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 中 就可以處理大部分的警告了
ios警告:Category is implementing a method which will also be implemented by its primary class 引發的相關處理