简化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);
posted @ 2016-04-08 19:36  zfyouxi  阅读(275)  评论(0编辑  收藏  举报