Skip to content

Instantly share code, notes, and snippets.

@itsthejb
Created July 4, 2014 13:29
Show Gist options
  • Select an option

  • Save itsthejb/c81c84fc49c06b41fb8a to your computer and use it in GitHub Desktop.

Select an option

Save itsthejb/c81c84fc49c06b41fb8a to your computer and use it in GitHub Desktop.
DataSource / Delegate generic message forwarding
#pragma mark Delegate / data source message forwarding
- (BOOL)respondsToSelector:(SEL)aSelector {
return ([super respondsToSelector:aSelector] ||
[self.dataSource respondsToSelector:aSelector] ||
[self.delegate respondsToSelector:aSelector]);
}
- (void)forwardInvocation:(NSInvocation *)invocation
{
if ([self.delegate respondsToSelector:[invocation selector]]) {
[invocation invokeWithTarget:self.delegate];
}
else if ([self.dataSource respondsToSelector:[invocation selector]]) {
[invocation invokeWithTarget:self.dataSource];
}
else {
[super forwardInvocation:invocation];
}
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
{
NSMethodSignature *signature = [super methodSignatureForSelector:selector];
if (!signature) {
signature = [(id) self.delegate methodSignatureForSelector:selector];
}
if (!signature) {
signature = [(id) self.dataSource methodSignatureForSelector:selector];
}
return signature;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment