| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ | |||
| 4 | 4 | [](https://travis-ci.org/radex/SwiftyTimer) | |
| 5 | 5 | [](https://cocoapods.org/pods/SwiftyTimer) | |
| 6 | 6 | [](#carthage) | |
| 7 | -  | ||
| 7 | +  | ||
| 8 | 8 | ||
| 9 | 9 | #### Modern Swifty API for `NSTimer` | |
| 10 | 10 | ###### SwiftyTimer allows you to instantly schedule delays and repeating timers using convenient closure syntax. It's time to get rid of Objective-C cruft. | |
@@ -13,14 +13,14 @@ Read [Swifty APIs: NSTimer](http://radex.io/swift/nstimer/) for more information | |||
| 13 | 13 | ||
| 14 | 14 | ## Usage | |
| 15 | 15 | ||
| 16 | - You can easily schedule repeating and non-repeating timers (repeats and delays) using `NSTimer.every` and `NSTimer.after`: | ||
| 16 | + You can easily schedule repeating and non-repeating timers (repeats and delays) using `Timer.every` and `Timer.after`: | ||
| 17 | 17 | ||
| 18 | 18 | ```swift | |
| 19 | - NSTimer.every(0.7.seconds) { | ||
| 19 | + Timer.every(0.7.seconds) { | ||
| 20 | 20 | statusItem.blink() | |
| 21 | 21 | } | |
| 22 | 22 | ||
| 23 | - NSTimer.after(1.minute) { | ||
| 23 | + Timer.after(1.minute) { | ||
| 24 | 24 | println("Are you still here?") | |
| 25 | 25 | } | |
| 26 | 26 | ``` | |
@@ -40,15 +40,15 @@ You can specify time intervals with these intuitive helpers: | |||
| 40 | 40 | You can pass method references instead of closures: | |
| 41 | 41 | ||
| 42 | 42 | ```swift | |
| 43 | - NSTimer.every(30.seconds, align) | ||
| 43 | + Timer.every(30.seconds, align) | ||
| 44 | 44 | ``` | |
| 45 | 45 | ||
| 46 | 46 | ### Manual scheduling | |
| 47 | 47 | ||
| 48 | 48 | If you want to make a timer object without scheduling, use `new(after:)` and `new(every:)`: | |
| 49 | 49 | ||
| 50 | 50 | ```swift | |
| 51 | - let timer = NSTimer.new(every: 1.second) { | ||
| 51 | + let timer = Timer.new(every: 1.second) { | ||
| 52 | 52 | println(self.status) | |
| 53 | 53 | } | |
| 54 | 54 | ``` | |
@@ -59,15 +59,15 @@ Call `start()` to schedule timers created using `new`. You can optionally pass t | |||
| 59 | 59 | ||
| 60 | 60 | ```swift | |
| 61 | 61 | timer.start() | |
| 62 | - timer.start(modes: NSDefaultRunLoopMode, NSEventTrackingRunLoopMode) | ||
| 62 | + timer.start(modes: .defaultRunLoopMode, RunLoopMode(NSEventTrackingRunLoopMode)) // Ugly, yes: rdar://27509030 | ||
| 63 | 63 | ``` | |
| 64 | 64 | ||
| 65 | 65 | ### Invalidation | |
| 66 | 66 | ||
| 67 | - If you want to invalidate a repeating timer on some condition, you can take an `NSTimer` argument in the closure you pass in: | ||
| 67 | + If you want to invalidate a repeating timer on some condition, you can take a `Timer` argument in the closure you pass in: | ||
| 68 | 68 | ||
| 69 | 69 | ```swift | |
| 70 | - NSTimer.every(5.seconds) { (timer: NSTimer) in | ||
| 70 | + Timer.every(5.seconds) { (timer: Timer) in | ||
| 71 | 71 | // do something | |
| 72 | 72 | ||
| 73 | 73 | if finished { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments