Last active
August 29, 2015 14:03
-
-
Save collindonnell/99f392901fb425d6b3d8 to your computer and use it in GitHub Desktop.
Notify a target with the specified arguments only if it responds to a selector.
This file contains 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
- (void)safelyMessageTarget:(id)target withSelector:(SEL)selector arguments:(NSArray *)arguments { | |
if ([target respondsToSelector:selector]) { | |
NSMethodSignature *methodSignature = [NSMethodSignature methodSignatureForSelector:selector]; | |
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; | |
[arguments enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { | |
[invocation setArgument:(__bridge void *)(obj) atIndex:idx]; | |
}]; | |
[invocation invokeWithTarget:target]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment