带有at符号(@)的Objective-C宏的含义 [英] Meaning of Objective-C macros prefixed with an at (@) symbol

查看:149
本文介绍了带有at符号(@)的Objective-C宏的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ReactiveCocoa框架使用weakifystrongify宏,这两个宏均以'@'符号开头.

The ReactiveCocoa framework makes use of weakify and strongify macros, both of which are preceded by an '@' symbol.

这里是一个示例(来自此文件).

Here's an example (From this file).

- (RACSignal *)rac_textSignal {
        @weakify(self);
        return [[[[RACSignal
                ... 
               ];
}

作为宏名称前缀的at符号的含义是什么? (注意:我已经检查了宏,它被称为"weakify",而不是"@weakify",因此它不仅仅是宏名!).

What is the significance of the at symbol that is a prefix to the macro name? (NOTE: I have checked the macro, and it is called 'weakify', not '@weakify', so it isn't just the macro name!).

宏本身在这里定义:

https://github.com/jspahrsummers/libextobjc/blob/master/extobjc /EXTScope.h#L45

推荐答案

@开头的宏没有特殊含义.这是在libextobjc中完成的,以使@weakify@strongify宏在语言的其余部分中看起来更加惯用.

There is no special meaning to macros starting with an @. This is done in libextobjc to make the @weakify and @strongify macros seem more idiomatic with the rest of the language.

从技术上讲,@不是宏的一部分.宏只是weakifystrongify.但是,宏的实际主体是这样编写的,除非在其前加上@,否则它将不会编译.这是通过在宏的开头添加一个空的@autoreleasepool {}来实现的,但是要删除开头的@.

Technically, the @ is not part of the macro. The macro is just weakify or strongify. The actual body of the macro, though, is written such that it will not compile unless preceded with an @. This is done by adding an empty @autoreleasepool {} at the beginning of the macro, but stripping off the leading @.

这篇关于带有at符号(@)的Objective-C宏的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆