Swiftpack.co -  seanmcneil/Thrimer as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
seanmcneil/Thrimer
A Swift package to support a Timer that may be paused and resumed.
.package(url: "https://github.com/seanmcneil/Thrimer.git", from: "1.0.1")

Thrimer

Requirements

Version 1.0

  • iOS 13.0+
  • Xcode 12.4+
  • Swift 5.5+

Instructions

Basic setup

Import the framework:

import Thrimer

It is recommended that you set an instance variable for Thrimer:

class ViewController: UIViewController {
var thrimer: Thrimer?

Express setup with Publisher

Initialize your property and start automatically, creating a non-repeating timer that runs for 10 seconds.

thrimer = Thrimer(interval: 10.0, repeats: false)

Standard timer

Initialize your property, the following creates a non-repeating timer that runs for 10 seconds and does not auto start.

thrimer = Thrimer(interval: 10.0, repeats: false, autostart: false)

And start the timer when you are ready:

thrimer?.start()

Pause timer

This creates a non-repeating timer with a 10 second duration.

let thrimer = Thrimer(interval: 10.0, repeats: false, autostart: false)
thrimer.start()

Once the timer is running, you can now pause it:

thrimer.pause()

You can check to see if it is paused:

if thrimer.isPaused  {
    print("Timer is paused")
}

You can check to see how much time is remaining on the timer:

print(thrimer.timeRemaining ?? "Timer is not paused")

Finally, you can resume it:

thrimer.resume()

Stop timer

If you need to stop the timer:

thrimer.stop()

Support

If you find an issue or can think of an improvement, issues and pull requests are always welcome.

For pull requests, please be sure to ensure your work is covered with existing or new unit tests.

Author

Sean McNeil

License

Thrimer is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 0
Last commit: 15 hours ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API