Last active
August 29, 2015 14:21
-
-
Save Galarius/2beb8707df5440c75b7f to your computer and use it in GitHub Desktop.
caching whether a delegate 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
@protocol SomeDelegate <NSObject> | |
- (void)someMethod:(id)item; | |
@end | |
@interface SomeInterface : NSObject | |
@property (nonatomic, weak) id <SomeDelegate> delegate; | |
@end | |
@implementation SomeInterface { | |
struct { | |
unsigned int someMethod:1; | |
} delegateRespondsTo; | |
} | |
- (void)setDelegate:(id <SomeDelegate>)delegate { | |
if (_delegate != delegate) { | |
_delegate = delegate; | |
delegateRespondsTo.someMethod = [_delegate respondsToSelector:@selector(someMethod:)]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment