Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@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
}
@maxgalbu
Copy link
Author

maxgalbu commented Feb 21, 2015

To use it as a pod, use this line in your Podfile:

pod 'NSObject+Debounce', :git => 'https://gist.github.com/maxgalbu/bec9cdb035051b0c4197.git'

@johanatan
Copy link

johanatan commented Oct 14, 2015

Is this going to stick around permanently though? Seems a little flaky to reference a pod defined in a gist.

@maxgalbu
Copy link
Author

maxgalbu commented Jan 13, 2016

If I put this in a github repository, would it stick permanently? I guess so, as long as I don't delete it. Same as this gist :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment