Skip to content

Swift SDK of Timer with Countdown, Repeat and After types

License

Notifications You must be signed in to change notification settings

osmanyildirim/OYTimer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cocoapods SPM compatible Platforms Swift Xcode MIT

Swift SDK of Timer with Countdown, Repeat and After types

Contents

Requirements

  • iOS 11.0+
  • Swift 5.0+

Installation

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"])
    ]
)

Usage

After

let timer = OYTimer(type: .after(5.second_s), interval: 1.second_s)

timer.start { [weak self] state, _, _ in
    if case .completed = state {
        // do stuff
    }
}

Countdown

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
    }
}

Repeat

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()
    }
}

License

OYTimer is released under an MIT license. See LICENSE for details.

About

Swift SDK of Timer with Countdown, Repeat and After types

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published