Meaning of Objective-C macros prefixed with an at (@) symbol

后端 未结 2 526
南方客
南方客 2021-02-04 05:29

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

Here\'s an example (From

相关标签:
2条回答
  • 2021-02-04 06:24

    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.

    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 @.

    0 讨论(0)
  • 2021-02-04 06:27

    The @ isn't part of the macro. weakify is defined as:

    #define weakify(...) \
        autoreleasepool {} \
        metamacro_foreach_cxt(ext_weakify_,, __weak, __VA_ARGS__)
    

    So @weakify(self) becomes:

    @autorelease {} metamacro_foreach_cxt(ext_weakify_,, __weak, self)
    
    0 讨论(0)
提交回复
热议问题