| [ Web Proxy ] |
| Viewing: https://cocoapods.org/pods/SwiftyTimer | [Back] [Original] |
CocoaPods trunk is moving to be read-only. Read more on the blog, there are 3 months to go.
| TestsTested | |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Oct 2018 |
| SPMSupports SPM |
Maintained by Radek Pietruszewski, Macbook.
[Platforms]
[CI Status]
[CocoaPods]
[Carthage compatible]
[Swift version]
NSTimerRead Swifty APIs: NSTimer for more information about this project.
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.daysYou can pass method references instead of closures:
Timer.every(30.seconds, align)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)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()
}
}Note: If you're running Swift 2, use SwiftyTimer 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 installThen import the library in all files where you use it:
import SwiftyTimerJust add to your Cartfile:
github "radex/SwiftyTimer"Simply copy Sources/SwiftyTimer.swift to your Xcode project.
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:
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.
Dimitris Koutsogiorgas, Danielle Lancashire, Eric Amorde, Igor Makarov, Orta Therox, Paul Beusterien, Samuel Giddins, and The CocoaPods Dev Team with contributions from many, many others.
Artsy, Button, Capital One, CircleCI, Discontinuity, Emerge Tools, Fingertips, Google, Heroku, jsDelivr, Realm, PSPDFKit, RubyMotion, Sauspiel, Slack, SoundCloud, Stripe, Square, and Technology Astronauts.
| Web Proxy Viewer | New URL | Original Page |