forwardingTargetForSelector
2017-03-21 本文已影响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,想想两者的不同以及相同点,能否达到一致的效果