A simple Swift Library for a Debouncer class to delay function calls
A Swift Library for a debounce function, similar to the JavaScript debounce. The Debouncer will delay a function call, and every time it's getting called it will delay the preceding call until the delay time is over.
Usage is as simple as the following code:
let d = Debouncer(delay: 10)
d.callback = {
// your code here
}
d.call()
You can pass a parameter delay
(in ms
of type TimerInterval) and optional an callback function.
Make sure to check out the Unit Tests for further code samples.
callback
Callback that is getting called when the timer firesdelay
Delay Time in msfireDate
Next Date when the Debouncer will fire
call
Call debouncer to start the callback after the delayed time. Multiple calls will ignore the older calls and overwrite the firing time
You can install the library to your project by using CocoaPods. Add the following code to your Podfile
:
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
pod 'SwiftDebouncer'
end
You can add the project as a git submodule
. Simply drag the SwiftDebouncer.xcodeproj
file into your Xcode project.
Don't forget to add the framework in your application target
Just copy and paste the Debouncer.swift
file into your project.
- This was developed to not copy over and over the same classes due different projects
- Test coverage should be pretty good - was developed using TDD
- Oriented on this article on how to deploy this on CocoaPods
- Contributors are very welcome