警告

Category is implementing a method which will also be implemented by its primary class

这个警告的意思是, 在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.

苹果官方文档Customizing existing classes中如下描述:

If the name of a method declared in a category is the same as a method in the original class, or a method in another category on the same class (or even a superclass), the behavior is undefined as to which method implementation is used at runtime.

这个警告说明, 类目中添加的这个方法和原类的方法名一致, 运行的时候会执行这个方法, 而且也会执行原类中的方法. 苹果官方文档中又说明,如果在类别中声明的方法的名称与原始类中的方法相同,或者在同一类(或甚至超类)上的另一类中的方法相同,那么该行为对于使用哪种方法实现是未定义的运行。 如果您使用自己的类使用类别,那么这不太可能成为问题,但是在使用类别添加标准Cocoa或Cocoa Touch类的方法时可能会导致问题。

解决方案

  1. 用继承的方式重写父类方法
  2. 用类目重写原类的方法, 需要通过runtime的method swizzling来进行方法IMP的交换处理.
  3. 忽略警告处理
    1>代码方式
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
// your override
#pragma clang diagnostic pop

2>Xcode设置方式:
在target的 build settings下 搜索other warning flags 然后给其添加 -Wno-objc-protocol-method-implementation

注: 这里的警告忽略的处理方法不能改变原警告造成的问题, 只能是屏蔽掉了警告, 所以当前方法和原类的方法都还是会执行的.

拓展

在忽略警告的处理上, 你可以在项目运行的时候, 右键警告选择 reveal in log 就可以在警告详情中发现 -Wobjc-protocol-method-implementation 这么一个格式的字段 在-W后添加一个no- ,然后添加到 other warning flags 中 就可以忽略你这些警告了.

参考资料:
Suppress warning “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相关推荐

  1. Java-IntelliJ IDEA【@Override is not allowed when implementing interface method 解决方法】

    idea导入maven项目 报"Override is not allowed when implementing interface method"_fighting_wzc的博 ...

  2. IDEA @Override is not allowed when implementing interface method(转载)

    近期研究idea,在编码过程发现报错:@Override is not allowed when implementing interface method .找到一个老外的回答,感觉挺有用的,记录下 ...

  3. react native : Implementing unavailable method

    Showing All Messages /Users/bl/bailing_work/projects/RNddk/RNddk/node_modules/react-native/Libraries ...

  4. @Override is not allowed when implementing interface method 的解决办法

    最近重装了系统后发现idea每次创建的Maven项目 中 继承类覆写方法的时候 @Override会报一个 @Override is not allowed when implementing int ...

  5. java @Override is not allowed when implementing interface method

    用idea写Java接口,写完接口,定义完方法,写实现类,实现类中实现接口方法,方法上边写@Override注解.报错,在注解上发现报错:@Override is not allowed when i ...

  6. 【Java】 @Override is not allowed when implementing interface method

    [问题描述] IDEA开发中遇到了如下问题: @Override is not allowed when implementing interface method [解决办法] File--> ...

  7. Idea报错:@Override is not allowed when implementing interface method

    在IntelliJ IDEA使用时报错: @Override is not allowed when implementing interface method 这是由于module的language ...

  8. idea报 @Override is not allowed when implementing interface method解决方法

    @Override is not allowed when implementing interface method的解决办法: 第一种: 将Language level改成图中所示 选择Modul ...

  9. 【解决】NotImplementedException: The method or operation is not implemented.

    开发平台:Unity 2018版本以上 编程语言:CSharp 6.0 以上 编译平台:Visual Studio   一.问题截图   二.问题描述 问题描述 原 文 NotImplementedE ...

  10. @Override is not allowed when implementing interface method

    用idea打开项目,有下划线 解决办法: 选中出现红色下划线的项目,右键单击,选择open module settings 将language level改为8-Lambdas- 点击apply 选择 ...

最新文章

  1. 小白程序员仅用5分钟入职BAT,他只做了这件事!
  2. 山西流感就诊比持续上升 专家为民答疑解惑
  3. python 基本模块 random、os、sys
  4. angr学习笔记(3)
  5. Unity3D - UGUI的手动搭建
  6. 聊一聊Load Average
  7. L-BFGS算法/Broyden族/BFGS算法/阻尼牛顿法的Python实现代码
  8. cocos2dx中关于Action动作的相关API的具体介绍
  9. php中取整的函数,php中四舍五入取整函数详细介绍
  10. 使用PowerShel导入和导出Hyper-v虚拟机
  11. 收藏:如何获取当前已经打开的IE对象(VB6代码)
  12. php模糊搜索 变量,自定义搜索seo变量{param}字符串
  13. 微软ReportViewer(rdlc)发布时所需要的动态库(vs2010)
  14. php无框架开发web项目,web.framework
  15. matlab下载安装教程
  16. 28款超级绿色版杀软,奉献给各位!【迅雷下载】
  17. H5表单中时间日期控件
  18. ip地址与交换机工作原理
  19. L298N驱动直流电机转动
  20. 将毫秒值(currentTimeMillis)转换为(年-月-日 时-分-秒)的形式,只需一行代码

热门文章

  1. saltstack实战--远程执行之返回(returner)
  2. flutter TextField删除文字后光标跑到文字末尾
  3. 考研数学复习笔记——行列式1
  4. java 文件图标_如何用java程序修改文件夹默认图标,麻烦了
  5. python识别屏幕内容_python之屏幕抓取
  6. 利用Docker 基于Uptime Kuma搭建服务器监控
  7. vue首次赋值不触发watch
  8. 分享一种免费的.FLV格式视频转.MP4的方法,方便高效且不用迅捷转换器。。。
  9. opencv将RGB转成YIQ
  10. linux ipcs字段含义 共享内存删除 ipcs dest状态