消息转送
- (BOOL)respondsToSelector:(SEL)aSelector {
if ([super respondsToSelector:aSelector]) {
return YES;
} else if ([self methodForSelector:aSelector] != (IMP)NULL) {
return YES;
} else {
return [self.someObj respondsToSelector:aSelector];
}
return NO;
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
if ([super respondsToSelector:aSelector]) {
return [super methodSignatureForSelector:aSelector];
}
return [self.someObj methodSignatureForSelector:aSelector];
}
- (void)forwardInvocation:(NSInvocation *)anInvocation {
SEL selector = [anInvocation selector];
if ([self.someObj respondsToSelector:selector]) {
[anInvocation invokeWithTarget:self.third];
} else {
[super forwardInvocation:anInvocation];
}
}
消息禁用
- (void)setSize:(NSSize *)size {
[self doesNotRecognizeSelector:_cmd];
}