关于__has_attribute的使用

在开源代码中我们经常看到如下的代码

#ifndef ASDISPLAYNODE_REQUIRES_SUPER
#if __has_attribute(objc_requires_super)
#define ASDISPLAYNODE_REQUIRES_SUPER __attribute__((objc_requires_super))
#else
#define ASDISPLAYNODE_REQUIRES_SUPER
#endif
#endif


一直很疑惑

__attribute__((objc_requires_super))

是干嘛用的,今天特地查了下,官网解释如下:

Some Objective-C classes allow a subclass to override a particular method in a parent class but expect that the overriding method also calls the overridden method in the parent class. For these cases, we provide an attribute to designate that a method requires a “call to super” in the overriding method in the subclass.

简单来说就是子类继承父类的某个方法时,如果在父类的该方法后面加了该属性,子类中如果没有调用父类的super方法,编译器则会有告警。

如下图:

150700_6RMn_734027.png

更多的相关介绍见Clang官网介绍


转载于:https://my.oschina.net/petsatan/blog/425676

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值