Skip to content

Instantly share code, notes, and snippets.

@JulesMoorhouse
Forked from maxgalbu/NSObject+Debounce.h
Created December 9, 2018 15:40
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 JulesMoorhouse/57506e43f70c92d79f637327f7e4f04a to your computer and use it in GitHub Desktop.
Save JulesMoorhouse/57506e43f70c92d79f637327f7e4f04a 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
{
"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/berzniz/8618806.git",
"commit": "d74b411a0850cb09960fed8189790b53d505cb26"
},
"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