-
-
Save marksands/0aa06ccde8bc5a4633e4f49fddcb73d9 to your computer and use it in GitHub Desktop.
Revisions
-
berzniz created this gist
Jan 25, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ @interface NSObject (Debounce) - (void)debounce:(SEL)action delay:(NSTimeInterval)delay; @end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ @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