All Projects → radex → Swiftytimer

radex / Swiftytimer

Licence: mit
Swifty API for NSTimer

Programming Languages

swift
15916 projects

Labels

Projects that are alternatives of or similar to Swiftytimer

Node Measured
A Node metrics library for measuring and reporting application-level metrics, inspired by Coda Hale, Yammer Inc's Dropwizard Metrics Libraries
Stars: ✭ 500 (-56.26%)
Mutual labels:  timer
Update Background Locations
A sample iOs example that tracks background locations.
Stars: ✭ 7 (-99.39%)
Mutual labels:  timer
Obs Studio Python Scripting Cheatsheet Obspython Examples Of Api
⚫️ OBS Studio API with Python
Stars: ✭ 40 (-96.5%)
Mutual labels:  timer
Easytimer.js
Easy to use Timer/Stopwatch/Countdown library compatible with AMD, ES6 and Typescript
Stars: ✭ 562 (-50.83%)
Mutual labels:  timer
Rulerview
卷尺系列控件,包含:普通卷尺(如:体重)、金额尺、时间尺
Stars: ✭ 816 (-28.61%)
Mutual labels:  timer
Appserver
A multithreaded application server for PHP, written in PHP.
Stars: ✭ 930 (-18.64%)
Mutual labels:  timer
Mob
Tool for swift git handover.
Stars: ✭ 418 (-63.43%)
Mutual labels:  timer
Countdowntask
⌛️A countdown library for Android.
Stars: ✭ 64 (-94.4%)
Mutual labels:  timer
Zltoolkit
一个基于C++11的轻量级网络框架,基于线程池技术可以实现大并发网络IO
Stars: ✭ 838 (-26.68%)
Mutual labels:  timer
Prince
Implementing PopRouting
Stars: ✭ 11 (-99.04%)
Mutual labels:  timer
Countdownlabel
Simple countdown UILabel with morphing animation, and some useful function.
Stars: ✭ 714 (-37.53%)
Mutual labels:  timer
Each
Elegant ⏱ interface for Swift apps
Stars: ✭ 764 (-33.16%)
Mutual labels:  timer
Mycodo
An environmental monitoring and regulation system
Stars: ✭ 936 (-18.11%)
Mutual labels:  timer
Wecron
✔️ 微信上的定时提醒 - Cron on WeChat
Stars: ✭ 537 (-53.02%)
Mutual labels:  timer
Ttimer
Terminal countdown timer, written in Go
Stars: ✭ 42 (-96.33%)
Mutual labels:  timer
React Idle Timer
User activity timer component
Stars: ✭ 420 (-63.25%)
Mutual labels:  timer
Flutter timer and stopwatch
A Timer with all the functionality you would expect. Both Inputs and Outputs are of type Duration.
Stars: ✭ 18 (-98.43%)
Mutual labels:  timer
Alfred Time
Start and stop tracking time with Toggl, Harvest, Everhour or Clockify through Alfred 4
Stars: ✭ 65 (-94.31%)
Mutual labels:  timer
React Countdown
React Component showing a countdown to certain date and time.
Stars: ✭ 58 (-94.93%)
Mutual labels:  timer
Dinnertime
Cooking timer & scheduler with spoken instructions
Stars: ✭ 7 (-99.39%)
Mutual labels:  timer

SwiftyTimer

Platforms CI Status CocoaPods Carthage compatible Swift version

Modern Swifty API for NSTimer

SwiftyTimer allows you to instantly schedule delays and repeating timers using convenient closure syntax. It's time to get rid of Objective-C cruft.

Read Swifty APIs: NSTimer for more information about this project.

Usage

You can easily schedule repeating and non-repeating timers (repeats and delays) using Timer.every and Timer.after:

Timer.every(0.7.seconds) {
    statusItem.blink()
}

Timer.after(1.minute) {
    println("Are you still here?")
}

You can specify time intervals with these intuitive helpers:

100.ms
1.second
2.5.seconds
5.seconds
10.minutes
1.hour
2.days

You can pass method references instead of closures:

Timer.every(30.seconds, align)

Manual scheduling

If you want to make a timer object without scheduling, use new(after:) and new(every:):

let timer = Timer.new(every: 1.second) {
    println(self.status)
}

(This should be defined as an initializer, but a bug in Foundation prevents this)

Call start() to schedule timers created using new. You can optionally pass the run loop and run loop modes:

timer.start()
timer.start(modes: .defaultRunLoopMode, .eventTrackingRunLoopMode)

Invalidation

If you want to invalidate a repeating timer on some condition, you can take a Timer argument in the closure you pass in:

Timer.every(5.seconds) { (timer: Timer) in
    // do something
    
    if finished {
        timer.invalidate()
    }
}

Installation

Note: If you're running Swift 2, use SwiftyTimer v1.4.1

CocoaPods

If you're using CocoaPods, just add this line to your Podfile:

pod 'SwiftyTimer'

Install by running this command in your terminal:

pod install

Then import the library in all files where you use it:

import SwiftyTimer

Carthage

Just add to your Cartfile:

github "radex/SwiftyTimer"

Manually

Simply copy Sources/SwiftyTimer.swift to your Xcode project.

More like this

If you like SwiftyTimer, check out SwiftyUserDefaults, which applies the same swifty approach to NSUserDefaults.

You might also be interested in my blog posts which explain the design process behind those libraries:

Contributing

If you have comments, complaints or ideas for improvements, feel free to open an issue or a pull request.

Author and license

Radek Pietruszewski

SwiftyTimer is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].