Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Debounce method for Objective C
@interface NSObject (Debounce)
- (void)debounce:(SEL)action delay:(NSTimeInterval)delay;
@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];
Copy link

maxgalbu commented Feb 19, 2015

Here's my fork that adds a podspec file:

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

pod 'NSObject+Debounce', :git => ''

Copy link

AntiMoron commented Dec 13, 2017

Awesome. Much shorter and better than my colleague's implementation. I've introduced this to him.

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