-
-
Save misterwell/3d12ee490a8c9e7cc6393bbc796e08c5 to your computer and use it in GitHub Desktop.
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
@interface NSObject (Debounce) | |
- (void)debounce:(SEL)action delay:(NSTimeInterval)delay; | |
- (void)debounce:(SEL)action object:(id)obj delay:(NSTimeInterval)delay; | |
@end |
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
@implementation NSObject (Debounce) | |
- (void)debounce:(SEL)action object:(id)obj delay:(NSTimeInterval)delay | |
{ | |
__weak typeof(self) weakSelf = self; | |
[NSObject cancelPreviousPerformRequestsWithTarget:weakSelf selector:action object:obj]; | |
[weakSelf performSelector:action withObject:obj afterDelay:delay]; | |
} | |
- (void)debounce:(SEL)action delay:(NSTimeInterval)delay | |
{ | |
[self debounce:action object:nil delay:delay]; | |
} | |
@end |
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
{ | |
"name": "NSObject+Debounce", | |
"version": "1.0.0", | |
"summary": "Debounce selector for specific delay", | |
"homepage": "https://gist.github.com/berzniz/8618806", | |
"license": "MIT", | |
"authors": "berzniz", | |
"source": { | |
"git": "https://gist.github.com/misterwell/3d12ee490a8c9e7cc6393bbc796e08c5", | |
"commit": "3d12ee490a8c9e7cc6393bbc796e08c5" | |
}, | |
"platforms": { | |
"ios": "6.0" | |
}, | |
"source_files": [ | |
"*.{h,m}" | |
], | |
"requires_arc": true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment