SwiftDebouncer

Swift Debouncer Library to delay function calls


Keywords
cocoapods, debounce, debouncing, delay, framework, ios, library, macos, swift
License
MIT
Install
pod try SwiftDebouncer

Documentation

SwiftDebouncer

A simple Swift Library for a Debouncer class to delay function calls

Badge w/ Version Language iOS GitHub license

Description

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.

Getting started

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.

Properties

  • callback Callback that is getting called when the timer fires
  • delay Delay Time in ms
  • fireDate Next Date when the Debouncer will fire

Functions

  • call Call debouncer to start the callback after the delayed time. Multiple calls will ignore the older calls and overwrite the firing time

Installation

CocoaPods

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

Git Submodule

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

Manually

Just copy and paste the Debouncer.swift file into your project.

Analytics

About this

  • 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