### Install SwiftDebouncer via CocoaPods Source: https://github.com/xremix/swiftdebouncer/blob/master/README.md Add the library to your project by including the dependency in your Podfile. ```ruby platform :ios, '8.0' use_frameworks! target 'MyApp' do pod 'SwiftDebouncer' end ``` -------------------------------- ### Accessing Debouncer Fire Date Property Source: https://context7.com/xremix/swiftdebouncer/llms.txt Get the next scheduled execution time of the callback using the read-only `fireDate` property. This will be nil if the debouncer has not been called or the timer has already fired. Ensure SwiftDebouncer is imported. ```swift import SwiftDebouncer let debouncer = Debouncer(delay: 5.0) { print("Timer fired!") } // Before calling - fireDate is nil print("Fire date before call: \(String(describing: debouncer.fireDate))") // Output: Fire date before call: nil debouncer.call() // After calling - fireDate shows when callback will execute if let fireDate = debouncer.fireDate { print("Callback will fire at: \(fireDate)") // Output: Callback will fire at: 2024-01-15 10:30:05 +0000 (approximately 5 seconds from now) } ``` -------------------------------- ### Initialize Debouncer with Delay and Callback Source: https://context7.com/xremix/swiftdebouncer/llms.txt Create a Debouncer instance with both delay time and callback function in a single initialization call using trailing closure syntax. Ensure SwiftDebouncer is imported. ```swift import SwiftDebouncer // Create debouncer with delay and callback in one statement let searchDebouncer = Debouncer(delay: 0.3) { print("Performing search...") // Execute search API call here } // Trigger the debouncer searchDebouncer.call() ``` -------------------------------- ### Initialize and use Debouncer in Swift Source: https://github.com/xremix/swiftdebouncer/blob/master/README.md Create a Debouncer instance with a specified delay and trigger the callback using the call method. ```swift let d = Debouncer(delay: 10) d.callback = { // your code here } d.call() ``` -------------------------------- ### Debouncer Class Initialization Source: https://context7.com/xremix/swiftdebouncer/llms.txt Methods for initializing the Debouncer class with a specific delay and optional callback. ```APIDOC ## Debouncer Initialization ### Description Creates a new instance of the Debouncer class to manage delayed execution of a callback. ### Parameters - **delay** (TimeInterval) - Required - The delay time in seconds before the callback is executed. - **callback** (Closure) - Optional - The action to be performed after the delay. ### Request Example // Initialize with delay only let debouncer = Debouncer(delay: 0.5) // Initialize with delay and callback let searchDebouncer = Debouncer(delay: 0.3) { print("Performing search...") } ``` -------------------------------- ### Initialize Debouncer with Delay Time Source: https://context7.com/xremix/swiftdebouncer/llms.txt Create a Debouncer instance with a delay time. The callback function can be set separately after initialization. Ensure SwiftDebouncer is imported. ```swift import SwiftDebouncer // Create a debouncer with a 0.5 second delay let debouncer = Debouncer(delay: 0.5) // Set the callback that will be executed after the delay debouncer.callback = { print("Debounced action executed!") // Perform your delayed action here } // Trigger the debouncer - callback fires after 0.5 seconds if no more calls debouncer.call() ``` -------------------------------- ### Managing Multiple Independent Debouncers Source: https://context7.com/xremix/swiftdebouncer/llms.txt Demonstrates using multiple Debouncer instances with varying delay times to handle different UI and background tasks independently. ```swift import SwiftDebouncer class EditorViewController: UIViewController { // Quick debounce for UI updates private let uiDebouncer = Debouncer(delay: 0.1) // Longer debounce for auto-save private let autoSaveDebouncer = Debouncer(delay: 2.0) // Medium debounce for spell check private let spellCheckDebouncer = Debouncer(delay: 0.5) override func viewDidLoad() { super.viewDidLoad() uiDebouncer.callback = { [weak self] in self?.updateWordCount() } autoSaveDebouncer.callback = { [weak self] in self?.saveDraft() } spellCheckDebouncer.callback = { [weak self] in self?.runSpellCheck() } } func textDidChange(_ text: String) { // All three debouncers operate independently uiDebouncer.call() // Updates UI after 0.1s pause spellCheckDebouncer.call() // Checks spelling after 0.5s pause autoSaveDebouncer.call() // Saves draft after 2.0s pause } private func updateWordCount() { print("Word count updated") } private func saveDraft() { print("Draft auto-saved") } private func runSpellCheck() { print("Spell check complete") } } ``` -------------------------------- ### Debouncer Methods and Properties Source: https://context7.com/xremix/swiftdebouncer/llms.txt Core functionality for triggering the debounce timer and accessing configuration properties. ```APIDOC ## call() ### Description Starts or resets the debounce timer. If called multiple times, only the final call triggers the callback after the delay. ## delay (Property) ### Description A read-only property returning the configured delay interval in seconds. ## fireDate (Property) ### Description A read-only property returning the next scheduled Date for the callback execution, or nil if not scheduled. ## callback (Property) ### Description A settable closure property defining the action to execute when the timer fires. ``` -------------------------------- ### Using Debouncer in a ViewController Source: https://context7.com/xremix/swiftdebouncer/llms.txt Demonstrates how to use the Debouncer class within a UIViewController to handle text input changes. Each call to `debouncer.call()` resets the timer, ensuring the search is performed only after the user stops typing for the specified delay. Ensure SwiftDebouncer is imported. ```swift import SwiftDebouncer class SearchViewController: UIViewController { let debouncer = Debouncer(delay: 0.5) override func viewDidLoad() { super.viewDidLoad() debouncer.callback = { [weak self] in self?.performSearch() } } // Called every time user types a character func searchTextDidChange(_ text: String) { // Each call resets the timer - only executes after user stops typing for 0.5s debouncer.call() } private func performSearch() { print("Executing search after user stopped typing") } } ``` -------------------------------- ### Setting and Updating Debouncer Callback Source: https://context7.com/xremix/swiftdebouncer/llms.txt Modify the action executed by the debouncer by assigning a new closure to the `callback` property. This allows for dynamic changes to the debounced behavior. Ensure SwiftDebouncer is imported. ```swift import SwiftDebouncer let debouncer = Debouncer(delay: 1.0) // Set initial callback debouncer.callback = { print("First callback executed") } debouncer.call() // Callback can be changed dynamically debouncer.callback = { print("Updated callback executed") } debouncer.call() // After 1 second, prints: "Updated callback executed" ``` -------------------------------- ### Accessing Debouncer Delay Property Source: https://context7.com/xremix/swiftdebouncer/llms.txt Retrieve the configured delay time interval in seconds from a Debouncer instance using its read-only `delay` property. Ensure SwiftDebouncer is imported. ```swift import SwiftDebouncer let debouncer = Debouncer(delay: 2.0) // Access the configured delay time print("Delay is set to: \(debouncer.delay) seconds") // Output: Delay is set to: 2.0 seconds ``` -------------------------------- ### Preventing Rapid Button Taps with SwiftDebouncer Source: https://context7.com/xremix/swiftdebouncer/llms.txt Ensures an action executes only once after rapid button taps cease by using a Debouncer instance with a defined delay. ```swift import SwiftDebouncer import UIKit class SubmitViewController: UIViewController { private let submitDebouncer = Debouncer(delay: 0.3) @IBOutlet weak var submitButton: UIButton! override func viewDidLoad() { super.viewDidLoad() submitDebouncer.callback = { [weak self] in self?.submitForm() } } @IBAction func submitButtonTapped(_ sender: UIButton) { // User may tap multiple times rapidly // Only one submitForm() call will execute after tapping stops submitDebouncer.call() } private func submitForm() { print("Form submitted only once!") // Perform actual form submission } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.