简化delegate写法

标准的写法


简化后的宏

/**************************************************************/
// delegate 委托
/*
#define DelegateSelf( __fun ) \
if (_delegate && [_delegate respondsToSelector:@selector( __fun )]) { \
    [_delegate __x self];} 
 */
#define DelegateSelf( __fun ) Delegate( __fun, self)

/*
#define Delegate( __x ) \
if (_delegate && [_delegate respondsToSelector:@selector(__x)]) { \
[_delegate __x];} 
 */
#pragma mark - to  delegate被注册KVO时,isa会变, 判断delegate被释放?
#define Delegate( __fun, ...) \
if (_delegate && [_delegate respondsToSelector:@selector( __fun )]) { \
objc_msgSend(_delegate, @selector( __fun ), ## __VA_ARGS__);}

简化后的写法

DelegateSelf(bankCellClickPlus:);

Delegate(clickMedal:index:, self, sender.tag);

你可能感兴趣的:(ios,c,delegate,宏,标准,objective)