关于__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方法,编译器则会有告警。

如下图:

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

时间: 2024-08-12 05:34:26

关于__has_attribute的使用的相关文章

iOS: 聊聊 Designated Initializer(指定初始化函数)

iOS: 聊聊 Designated Initializer(指定初始化函数) 一.iOS的对象创建和初始化 iOS 中对象创建是分两步完成: 分配内存 初始化对象的成员变量 我们最熟悉的创建NSObject对象的过程: 苹果官方有一副图片更生动的描述了这个过程: 对象的初始化是一个很重要的过程,通常在初始化的时候我们会支持成员变量的初始状态,创建关联的对象等.例如对于如下对象: 1 @interface ViewController : UIViewController 2 3 @end 4

error: property's synthesized getter follows Cocoa naming convention for returning 'owned' objects

出现这种情况,主要是属性名中包含  关键字. You can solve this by: Renaming that property: @property (strong, nonatomic) NSString *theNewTitle; Keeping the property name and specifying a getter name that doesn't begin with one of the special method name prefixes: @proper

Error解决:Property's synthesized getter follows Cocoa naming convention for returning 'owned'

在项目中定义了以new开头的textField,结果报错: 先看我的源码: #import <UIKit/UIKit.h> @interface ResetPasswordViewController : UIViewController @property (weak, nonatomic) IBOutlet UITextField *phoneTextField; @property (weak, nonatomic) IBOutlet UITextField *oldPasswordTe

Swift和Objective-C混合编程

1. 首先打开Xcode6,建立一个项目,这里我使用的Objective-C默认的编程语言,项目名字叫 "SwiftAndObjective". 2. 为了在OC中使用Swift的演示所以需要建立下面的几个类. a)建立一个Objective-C的类继承自NSObject,名字叫OCTypeClass, 所以会自动产生两个对应的 .m 和 .h文件,这对熟悉Objective-C的人非常熟悉. b)  尽力一个Swift类,名字叫SwiftFile1, 在点击创建的时候,会弹出一个提示

深入研究Clang(六) Clang Lexer代码阅读笔记之Preprocesser

clang/include/clang/Lex/Preprocesser.h 这个文件是包含clang::Preprocesser类的定义的头文件.它是类C语言(C.C++.Object C)的预处理的头文件.也就是说,类C语言的预处理都会用到此处的代码. 00082 /// \brief Context in which macro name is used. 00083 enum MacroUse { 00084 MU_Other = 0, // other than #define or

AFNetworking汉化之“AFURLSessionManager”

1 声明 1.本文的写作目的是为学习记录,同时分享给大家,希望大神能够对文中错误的理解进行指正. 2.如果文章内容涉及到其他已经发表了,但文章中又未提及转载事项,请及时与本人联系. 3.本文为个人理解,如果部分知识点与真实情况有出入,请忽略本文. 2 前言 2.1 概述 虽然苹果的原生SDK中已经有很强大的网络请求API,例如NSURLSession.NSURLRequest等.但为了满足不同的网络需求,也同时为了代码简洁和易用性,诞生了许多第三方封装的网络框架.其中主流的包括ASIHTTPRe

AFNetworking 源码解析之“AFURLSessionManager”

[objc] view plain copy #import <Foundation/Foundation.h> #import "AFURLResponseSerialization.h" #import "AFURLRequestSerialization.h" #import "AFSecurityPolicy.h" #import "AFNetworkReachabilityManager.h" #ifnd

GCC 5 Release Series Changes, New Features, and Fi

GCC 5 Release Series Changes, New Features, and Fixes Caveats The default mode for C is now -std=gnu11 instead of -std=gnu89. The Graphite framework for loop optimizations no longer requires the CLooG library, only ISL version 0.14 (recommended) or 0

iOS: Designated Initializer(指定初始化函数)

一.iOS的对象创建和初始化 iOS 中对象创建是分两步完成: 分配内存 初始化对象的成员变量 我们最熟悉的创建NSObject对象的过程: 苹果官方有一副图片更生动的描述了这个过程: 对象的初始化是一个很重要的过程,通常在初始化的时候我们会支持成员变量的初始状态,创建关联的对象等.例如对于如下对象: Test ViewController 上面的VC中有一个成员变量XXService,在viewWillAppear的时候发起网络请求获取数据填充VC. 大家觉得上面的代码有没有什么问题? 带着这