美文网首页
forwardingTargetForSelector

forwardingTargetForSelector

作者: 谁在弹奏一曲东风破 | 来源:发表于2017-03-21 11:50 被阅读199次

    forwardingTargetForSelector用于对指定的selector的截获,然后转换成自己的selector,可以在NSObject子类中重载,如:

    - (id)forwardingTargetForSelector:(SEL)aSelector
     {
         if (aSelector == @selector(uppercaseString))
         {
             return@"hello world";
         }
     }
    
    - (id)forwardingTargetForSelector:(SEL)aSelector{
        NSString * selectorName = NSStringFromSelector(aSelector);
        if ([selectorName hasPrefix:@"draw"]) {
            [self apply];
        }
        return _component;
    }
    

    对此可以联系到swizzle,想想两者的不同以及相同点,能否达到一致的效果

    相关文章

      网友评论

          本文标题:forwardingTargetForSelector

          本文链接:https://www.haomeiwen.com/subject/rhumnttx.html