①通過(guò)
#define weakify(...) \
autoreleasepool {} \
metamacro_foreach_cxt(rac_weakify_,, __weak, __VA_ARGS__)
替換結(jié)果為:
@autoreleasepool{}
metamacro_foreach_cxt(rac_weakify_,, __weak, self)
//__VA_ARGS__為參數(shù)'...',當(dāng)前情況的參數(shù)為'self'
②根據(jù)
#define metamacro_foreach_cxt(MACRO, SEP, CONTEXT, ...) \
metamacro_concat(metamacro_foreach_cxt, metamacro_argcount(__VA_ARGS__))(MACRO, SEP, CONTEXT, __VA_ARGS__)
替換結(jié)果為:
@autoreleasepool{}
metamacro_concat(metamacro_foreach_cxt, metamacro_argcount(self))(rac_weakify_, ,__weak, self)
③通過(guò)
#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)
//返回當(dāng)前參數(shù)的個(gè)數(shù)
替換結(jié)果為:
@autoreleasepool{}
metamacro_concat(metamacro_foreach_cxt, 1)(rac_weakify_, ,__weak, self)
④通過(guò)
#define metamacro_concat_(A, B) A ## B
替換結(jié)果為:
@autoreleasepool{}
metamacro_foreach_cxt1(rac_weakify_, ,__weak, self)
⑤通過(guò)
#define metamacro_foreach_cxt1(MACRO, SEP, CONTEXT, _0) MACRO(0, CONTEXT, _0)
替換結(jié)果為:
@autoreleasepool{}
rac_weakify_(0,__weak,self)
⑥根據(jù)
define rac_weakify_(INDEX, CONTEXT, VAR) \
CONTEXT __typeof__(VAR) metamacro_concat(VAR, _weak_) = (VAR);
替換結(jié)果為:
@autoreleasepool{}
__weak __typeof__(self) self_weak_ = self;
注:Xcode 分屏preprocess顯示:
@autoreleasepool {} __attribute__((objc_ownership(weak))) __typeof__(self) self_weak_ = (self);;