Skip to content

Instantly share code, notes, and snippets.

@itsthejb
Created July 2, 2015 10:54
Show Gist options
  • Select an option

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

Select an option

Save itsthejb/795a75cd14db2f33fccf to your computer and use it in GitHub Desktop.
Child property forwarding
/**
* Forward any unimplemented methods to a particular object property
*/
#define FORWARD_TO_PROPERTY(PROPERTY) \
- (void)forwardInvocation:(NSInvocation *)anInvocation { \
if ([super respondsToSelector:anInvocation.selector]) { \
[super forwardInvocation:anInvocation]; \
} else { \
[anInvocation invokeWithTarget:PROPERTY]; \
} \
} \
- (BOOL)respondsToSelector:(SEL)aSelector { \
if (![super respondsToSelector:aSelector]) { \
return [PROPERTY respondsToSelector:aSelector]; \
} \
return YES; \
} \
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector { \
NSMethodSignature *signature = [super methodSignatureForSelector:aSelector]; \
if (!signature) { \
signature = [(id) PROPERTY methodSignatureForSelector:aSelector]; \
} \
return signature; \
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment