Skip to content

Latest commit

 

History

History
111 lines (86 loc) · 2.59 KB

README.md

File metadata and controls

111 lines (86 loc) · 2.59 KB

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.