Latest 1.0.3
Homepage https://github.com/anotheren/SwiftTimer
License MIT
Platforms ios 8.0, osx 10.11, watchos 3.0, tvos 10.0, requires ARC
Authors

[]() platforms

Simple and Elegant Timer

中文介绍:打造一个优雅的Timer

Compare with NSTimer

  • No retain cycle
  • Decouple with RunLoop
  • Support GCD queue
  • Support dynamically changing interval
  • Support closure syntax

Usage

single timer

let timer = SwiftTimer(interval: .seconds(2)) {
    print("fire")
}
timer.start()

repeatic timer

let timer = SwiftTimer.repeaticTimer(interval: .seconds(1)) {
    print("fire")
}
timer.start()

dynamically changing interval

let timer = SwiftTimer.repeaticTimer(interval: .seconds(5)) { timer in
    print("doSomething")
}
timer.start()  // print doSomething every 5 seconds

func speedUp(timer: SwiftTimer) {
    timer.rescheduleRepeating(interval: .seconds(1))
}
speedUp(timer) // print doSomething every 1 second 

throttle

SwiftTimer.throttle(interval: .seconds(0.5), identifier: "throttle") {
    search(inputText)
}

count down timer

let timer = SwiftCountDownTimer(interval: .fromSeconds(0.1), times: 10) { timer , leftTimes in
    label.text = "(leftTimes)"
}
timer.start()

Installation

CococaPods:

pod 'SwiftTimer', '~> 1.0.3'

Carthage:

github "100mango/SwiftTimer"

Latest podspec

{
    "name": "SwiftTimer",
    "version": "1.0.3",
    "summary": "Simple and Elegant Timer",
    "homepage": "https://github.com/anotheren/SwiftTimer",
    "license": {
        "type": "MIT"
    },
    "authors": {
        "liudong": "[email protected]"
    },
    "requires_arc": true,
    "platforms": {
        "ios": "8.0",
        "osx": "10.11",
        "watchos": "3.0",
        "tvos": "10.0"
    },
    "source": {
        "git": "https://github.com/anotheren/SwiftTimer.git",
        "tag": "1.0.3"
    },
    "source_files": "Sources/*.swift",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This