-
Notifications
You must be signed in to change notification settings - Fork 0
nevyn/delegationhelper
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The usual pattern is to do this in your class that has a delegate: -(void)frobnicate; { ... BOOL extraJuicy = NO; if(delegate && [delegate respondsToSelector:@selector(frobnicatorShouldAddJuice:)]) extraJuicy = [delegate frobnicatorShouldAddJuice:self]; if(extraJuicy) ... ... } for every delegation method, which gets old, fast. With DelegationHelper, you can do this: // Setup @interface FrobnicatorDelegationHelper : DelegationHelper <FrobnicatorDelegate> {} @end @interface Frobnicator... { FrobnicatorDelegationHelper *delegate; ... } ...@end @implementation -(void)setDelegate:(id<FrobnicatorDelegate>)delegate_ { delegate = [[DelegationHelper alloc] init]; delegate.delegate = delegate_; [delegate setDefaultDelegationObject:BOOLobj(YES) forSelector:(frobnicatorShouldAddJuice:)]; } // And then just... -(void)frobnicate; { ... if([delegate frobnicateShouldAddJuice:self]) ... ... } Okay, the setup requires three extra lines and one line per selector (for defaults), but we've cut down the actual delegate calls from four lines to one! So if you have more than a single delegate method for your class, the DelegationHelper will help you. For more samples, see main.m.
About
[Cocoa] You'll never need to write [delegate respondsToSelector:] again.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published