Created
July 4, 2014 13:29
-
-
Save itsthejb/c81c84fc49c06b41fb8a to your computer and use it in GitHub Desktop.
DataSource / Delegate generic message forwarding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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