- Notifications
You must be signed in to change notification settings - Fork136
radex/SwiftyTimer
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
SwiftyTimer allows you to instantly schedule delays and repeating timers using convenient closure syntax. It's time to get rid of Objective-C cruft.
ReadSwifty APIs: NSTimer for more information about this project.
You can easily schedule repeating and non-repeating timers (repeats and delays) usingTimer.every andTimer.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.ms1.second2.5.seconds5.seconds10.minutes1.hour2.days
You can pass method references instead of closures:
Timer.every(30.seconds, align)
If you want to make a timer object without scheduling, usenew(after:) andnew(every:):
lettimer=Timer.new(every:1.second){println(self.status)}
(This should be defined as an initializer, buta bug in Foundation prevents this)
Callstart() to schedule timers created usingnew. You can optionally pass the run loop and run loop modes:
timer.start()timer.start(modes:.defaultRunLoopMode,.eventTrackingRunLoopMode)
If you want to invalidate a repeating timer on some condition, you can take aTimer argument in the closure you pass in:
Timer.every(5.seconds){(timer:Timer)in // do somethingif finished{ timer.invalidate()}}
Note: If you're running Swift 2, useSwiftyTimer v1.4.1
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 SwiftyTimerJust add to your Cartfile:
github"radex/SwiftyTimer"
Simply copySources/SwiftyTimer.swift to your Xcode project.
If you like SwiftyTimer, check outSwiftyUserDefaults, which applies the same swifty approach toNSUserDefaults.
You might also be interested in my blog posts which explain the design process behind those libraries:
If you have comments, complaints or ideas for improvements, feel free to open an issue or a pull request.
Radek Pietruszewski
SwiftyTimer is available under the MIT license. See the LICENSE file for more info.
About
Swifty API for NSTimer
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.