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.  因此这里就出现了警告,警告而已,毕竟不是错误,因此也不会影响咱们的使用,可是会让人看着很不爽,因此查了一下不显示这个警告的方法xcode

1.在相关位置插入下面这段代码ide

#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-implementationui

好了  警告没有了spa

这里顺便说一下  2中的方法  对不少批量的警告颇有用  然后面相关字段 -Wno-objc-protocol-method-implementation  实际上是能够查获得的    方法是在xcode中选择你想屏蔽的警告,右键选择 reveal in log 就能够在警告详情中发现 -Wobjc-protocol-method-implementation  这么一个格式的字段 在-W后添加一个no-  而后在用2中的方法添加到 other warning flags 中 就能够处理大部分的警告了code

相关文章
相关标签/搜索