swift-persistable-timer

0.2.0

Persistent timers and stopwatches ensuring seamless state restoration
Ryu0118/swift-persistable-timer

What's New

v0.2.0

2024-03-27T04:01:51Z

What's Changed

New Contributors

Full Changelog: 0.1.0...0.2.0

PersistableTimer

Persistent timers and stopwatches ensuring seamless state restoration.

Example

Usage

Instantiate PersistableTimer with your choice of data source (UserDefaults or in-memory for testing and previewing purposes):

import PersistableTimer

let timer = PersistableTimer(dataSourceType: .inMemory)
let timer = PersistableTimer(dataSourceType: .userDefaults(.standard))
let timer = PersistableTimer(dataSourceType: .userDefaults(.standard), updateInterval: 0.5)

Starting a Timer

Start a stopwatch or countdown timer. Optionally force the start of a new timer even if another is running.

try await timer.start(type: .stopwatch)
// Start a countdown timer with a duration of 100 seconds
try await timer.start(type: .timer(duration: 100))

Pausing, Resuming, and Finishing

Pause and resume a running timer, or mark it as finished:

try await timer.pause()
try await timer.resume()
try await timer.finish(isResetTime: false)

Restoring Timer State

Restore the timer's state after an app restart:

try timer.restore()

Timer Updates

Subscribe to timer updates using the timeStream:

for await timeState in timer.timeStream {
    // Update your UI with the current timeState
    print(timerState.time)
}

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Apr 13 2024 12:23:15 GMT-0900 (Hawaii-Aleutian Daylight Time)