Skip to content

Instantly share code, notes, and snippets.

@soxjke
Created May 10, 2018 16:01
Show Gist options
  • Select an option

  • Save soxjke/0663911676daae69064dd6a5b7e5348b to your computer and use it in GitHub Desktop.

Select an option

Save soxjke/0663911676daae69064dd6a5b7e5348b to your computer and use it in GitHub Desktop.
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel {
NSMethodSignature * __block signature = nil;
[self.implementations enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
signature = [obj methodSignatureForSelector:sel];
*stop = (nil != signature);
}];
return signature;
}
- (BOOL)respondsToSelector:(SEL)aSelector {
BOOL __block result = NO;
[self.implementations enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
result = [obj respondsToSelector:aSelector];
*stop = result;
}];
return result;
}
- (void)forwardInvocation:(NSInvocation *)invocation {
BOOL __block result = NO;
@weakify(invocation)
[self.implementations enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
@strongify(invocation);
result = [obj respondsToSelector:invocation.selector];
if (result) {
[invocation invokeWithTarget:obj];
[invocation retainArguments];
}
*stop = result;
}];
if (!result) {
[super forwardInvocation:invocation];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment