Easy to use yet powerful Timer library. Keep your code clean
Timer is a free and open-source library dedicated for Swift that makes the process of handling timers easier and much cleaner.
publish().start()
method. Stop the timer with stop()
. Simple as never.Platforms | Minimum Swift Version |
---|---|
iOS 13+ | 5.0 |
Swift package manager is a tool for automating the distribution of Swift code and is integrated into the Swift compiler.
Once you have your Swift package set up, adding Timer as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/Mijick/Timer", branch(“main”))
]
Call the publish()
method that has three parameters:
try! MTimer.publish(every: 1, currentTime: $currentTime)
Start the timer using the start()
method. You can customise the start and end time using the parameters of this method.
try! MTimer
.publish(every: 1, currentTime: $currentTime)
.start(from: .init(minutes: 21, seconds: 37), to: .zero)
You can observe changes in both values by calling either of the methods
try! MTimer
.publish(every: 1, currentTime: $currentTime)
.bindTimerStatus(isTimerRunning: $isTimerRunning)
.bindTimerProgress(progress: $timerProgress)
.start(from: .init(minutes: 21, seconds: 37), to: .zero)
Timer can be stopped with stop()
method.
MTimer.stop()
resume()
method. try! MTimer.resume()
reset()
method. MTimer.reset()
You can convert the current MTime to String by calling the toString()
method. Use the formatter
parameter to customise the output.
currentTime.toString {
$0.unitsStyle = .full
$0.allowedUnits = [.hour, .minute]
return $0
}
Create a new instance of the timer and assign it to a new variable. Use the above functions directly with it
let newTimer = MTimer.createNewInstance()
try! newTimer
.publish(every: 1, currentTime: $currentTime)
.start()
newTimer.stop()
See for yourself how does it work by cloning project we created
Timer is released under the MIT license. See LICENSE for details.
PopupView - The most powerful popup library that allows you to present any popup
Navigattie - Easier and cleaner way of navigating through your app
GridView - Lay out your data with no effort
link |
Stars: 11 |
Last commit: 5 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics