6 private let queue = DispatchQueue.main
7 private var workItem = DispatchWorkItem(block: {})
8 private var interval: TimeInterval
10 // MARK: - Initializer
11 init(seconds: TimeInterval) {
12 self.interval = seconds
15 // MARK: - Debouncing function
16 func debounce(action: @escaping (() -> Void)) {
18 workItem = DispatchWorkItem(block: { action() })
19 queue.asyncAfter(deadline: .now() + interval, execute: workItem)