@weakify(self)解析

①通过

#define weakify(...)    \

    autoreleasepool {} \
    
    metamacro_foreach_cxt(rac_weakify_,, __weak, __VA_ARGS__)
    

替换结果为:

@autoreleasepool{}

metamacro_foreach_cxt(rac_weakify_,, __weak, self) 

//__VA_ARGS__为参数'...',当前情况的参数为'self'

②根据

#define metamacro_foreach_cxt(MACRO, SEP, CONTEXT, ...) \

        metamacro_concat(metamacro_foreach_cxt, metamacro_argcount(__VA_ARGS__))(MACRO, SEP, CONTEXT, __VA_ARGS__)

替换结果为:

@autoreleasepool{}

metamacro_concat(metamacro_foreach_cxt, metamacro_argcount(self))(rac_weakify_, ,__weak, 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)    
        //返回当前参数的个数

替换结果为:

@autoreleasepool{}

metamacro_concat(metamacro_foreach_cxt, 1)(rac_weakify_, ,__weak, self)

④通过

#define metamacro_concat_(A, B) A ## B

替换结果为:

@autoreleasepool{}

metamacro_foreach_cxt1(rac_weakify_, ,__weak, self)

⑤通过

#define metamacro_foreach_cxt1(MACRO, SEP, CONTEXT, _0) MACRO(0, CONTEXT, _0)

替换结果为:

@autoreleasepool{} 

rac_weakify_(0,__weak,self)

⑥根据

define rac_weakify_(INDEX, CONTEXT, VAR) \

    CONTEXT __typeof__(VAR) metamacro_concat(VAR, _weak_) = (VAR);

替换结果为:

@autoreleasepool{}  

__weak __typeof__(self) self_weak_ = self;

注:Xcode 分屏preprocess显示:

@autoreleasepool {} __attribute__((objc_ownership(weak))) __typeof__(self) self_weak_ = (self);;

参照:http://www.cocoachina.com/ios/20161025/17303.html

你可能感兴趣的:(@weakify(self)解析)