Skip to content

Instantly share code, notes, and snippets.

@madebyjeffrey
Created April 21, 2010 23:28
Show Gist options
  • Save madebyjeffrey/374576 to your computer and use it in GitHub Desktop.
Save madebyjeffrey/374576 to your computer and use it in GitHub Desktop.
/*
This code present a way to implement textView:doCommandBySelector, as sent by an NSTextView to its delegate, and implement the method as - (BOOL) method: (NSTextView*)aTextView and avoid the need for if statement chaining.
*/
- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector {
if ([self respondsToSelector: aSelector]) {
BOOL (*method)(id, SEL, NSTextView*);
method = (BOOL (*)(id, SEL, NSTextView*))[self methodForSelector: aSelector];
return method(self, aSelector, aTextView);
} else {
return NO;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment