A modern Swift API for NSTimer with intuitive closure syntax and time interval helpers.
SwiftyTimer is a Swift library that provides a modern, Swifty API wrapper around Apple's NSTimer. It simplifies scheduling delays and repeating timers in iOS, macOS, watchOS, and tvOS apps by replacing verbose Objective-C patterns with clean closure syntax and intuitive time interval helpers. The library solves the problem of cumbersome timer management in Swift, making code more readable and expressive.
Swift developers building apps for Apple platforms (iOS, macOS, watchOS, tvOS) who need to manage timers with less boilerplate and more type safety.
Developers choose SwiftyTimer for its elegant API that feels native to Swift, eliminating Objective-C cruft with features like closure-based scheduling, intuitive time helpers (e.g., `5.seconds`), and inline timer invalidation. It reduces code complexity while maintaining full control over timer behavior.
Swifty API for NSTimer
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Replaces verbose Objective-C target-selector patterns with clean Swift closures, making timer code more readable and less error-prone, as demonstrated in the README with examples like `Timer.every(0.7.seconds) { statusItem.blink() }`.
Provides natural time helpers such as `5.seconds` and `100.ms`, allowing intervals to be expressed in a human-readable way without manual unit conversions, enhancing code clarity and reducing bugs.
Offers manual scheduling with `new(after:)` and `new(every:)`, plus configurable run loop modes via `start(modes:)`, giving developers fine-grained control over timer execution and integration with different app states.
Enables conditional timer invalidation within the callback by passing a Timer argument, simplifying logic for stopping timers based on runtime conditions, as shown in the README with the `timer.invalidate()` example.
Relies on `new(after:)` and `new(every:)` methods instead of proper initializers due to a known bug in Foundation, which can feel less idiomatic and might confuse developers expecting standard Swift initialization patterns.
As a wrapper around NSTimer, it carries over issues like timing inaccuracies and dependency on run loops, making it unsuitable for applications requiring high-precision scheduling or real-time performance.
Lacks integration with Swift's newer concurrency models such as async/await or Combine, limiting its usefulness in projects adopting these technologies for timer-based operations and reactive programming.
Exclusively supports Apple platforms (iOS, macOS, watchOS, tvOS), so it cannot be used in cross-platform Swift projects targeting environments like Linux or Windows, restricting its versatility.