How can I use commercial at sign in Objective-C ma

2020-01-29 11:19发布

问题:

How can I use commercial at sign in Objective-C macro?

I know it is not recommended, but seems it is possible somehow? Since libextobjc provides @weakify, @strongify, etc...

回答1:

libextobjc uses preprocessor trickery to make you think it's an @command.

#define weakify(...) \
    try {} @finally {} \
    metamacro_foreach_cxt(ext_weakify_,, __weak, __VA_ARGS__)

Note the missing @ on the try. So @weakify expands into @try {} @finally {} [injected code].

You could use the same trick, but I suggest you stick with plain macros.