①通过
#define strongify(...) \
try {} @finally {} \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
metamacro_foreach(rac_strongify_,, __VA_ARGS__) \
_Pragma("clang diagnostic pop")
替换结果为:
@try {} @finally {}
metamacro_foreach(rac_strongify_,, __VA_ARGS__)
②通过
#define metamacro_foreach(MACRO, SEP, ...) \
metamacro_foreach_cxt(metamacro_foreach_iter, SEP, MACRO, __VA_ARGS__)
替换结果为:
@try {} @finally {}
metamacro_foreach_cxt(metamacro_foreach_iter, , rac_strongify_, self)
③通过
#define metamacro_foreach_cxt(MACRO, SEP, CONTEXT, ...) \
metamacro_concat(metamacro_foreach_cxt, metamacro_argcount(__VA_ARGS__))(MACRO, SEP, CONTEXT, __VA_ARGS__)
替换结果为:
@try {} @finally {}
metamacro_concat(metamacro_foreach_cxt, metamacro_argcount(self))(metamacro_foreach_iter,, rac_strongify_, self)
④通过
#define metamacro_argcount(...) \
metamacro_at(20, __VA_ARGS__, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
//返回当前参数的个数
替换结果为:
@try {} @finally {}
metamacro_concat(metamacro_foreach_cxt, 1)(metamacro_foreach_iter,, rac_strongify_, self)
⑤通过
#define metamacro_concat_(A, B) A ## B
替换结果为:
@try {} @finally {}
metamacro_foreach_cxt1(metamacro_foreach_iter,, rac_strongify_, self)
⑥通过
#define metamacro_foreach_cxt1(MACRO, SEP, CONTEXT, _0) MACRO(0, CONTEXT, _0)
替换结果为:
@try {} @finally {}
metamacro_foreach_iter(0,rac_strongify_, self)
⑦通过
#define metamacro_foreach_iter(INDEX, MACRO, ARG) MACRO(INDEX, ARG)
替换结果为:
@try {} @finally {}
rac_strongify_(0,self)
⑧通过
#define rac_strongify_(INDEX, VAR) \
__strong __typeof__(VAR) VAR = metamacro_concat(VAR, _weak_);
替换结果为:
@try {} @finally {}
__strong __typeof__(self) self = self_weak_;
注:Xcode 分屏preprocess显示:
@try {} @finally {}
__attribute__((objc_ownership(strong))) __typeof__(self) self = self_weak_;