Swift SDK of Timer with Countdown, Repeat and After types
- iOS 11.0+
- Swift 5.0+
CocoaPods
Add the following line to your Podfile
pod 'OYTimer'
Swift Package Manager
Add OYTimer as a dependency to your Package.swift and specify OYTimer as a target dependency
import PackageDescription let package = Package( name: "YOUR_PROJECT_NAME", targets: [], dependencies: [ .package(url: "https://github.com/osmanyildirim/OYTimer", .upToNextMinor(from: "1.0")), ], targets: [ .target( name: "YOUR_PROJECT_NAME", dependencies: ["OYTimer"]) ] )
let timer = OYTimer(type: .after(5.second_s), interval: 1.second_s) timer.start { [weak self] state, _, _ in if case .completed = state { // do stuff } }
The timer will be invalidate when state is
.completed
let timer = OYTimer(type: .countdown(1.minute_s), interval: 1.second_s) timer.start { [weak self] state, _, remaining in if case .ticking = state { print(remaining) } else if case .completed = state { // do stuff } }
let timer = OYTimer(type: .repeat, interval: 1.second_s) timer.start { [weak self] state, counter, _ in if case .ticking = state { print(counter) } if counter == 20 { timer.stop() } }
OYTimer is released under an MIT license. See LICENSE for details.
