Skip to content

Instantly share code, notes, and snippets.

@hagino3000
Forked from berzniz/NSObject+Debounce.h
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hagino3000/d71d7f4d76954874e0ad to your computer and use it in GitHub Desktop.
Save hagino3000/d71d7f4d76954874e0ad to your computer and use it in GitHub Desktop.
@interface NSObject (Debounce)
- (void)debounce:(SEL)action delay:(NSTimeInterval)delay;
@end
@implementation NSObject (Debounce)
- (void)debounce:(SEL)action delay:(NSTimeInterval)delay
{
__weak typeof(self) weakSelf = self;
[NSObject cancelPreviousPerformRequestsWithTarget:weakSelf selector:action object:nil];
[weakSelf performSelector:action withObject:nil afterDelay:delay];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment