| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,36 @@ | |||
| 25 | 25 | import Foundation | |
| 26 | 26 | ||
| 27 | 27 | extension NSTimer { | |
| 28 | + | ||
| 29 | + // MARK: Schedule timers | ||
| 30 | + | ||
| 31 | + /// Create and schedule a timer that will call `block` once after the specified time. | ||
| 32 | + | ||
| 33 | + public class func after(interval: NSTimeInterval, _ block: () -> Void) -> NSTimer { | ||
| 34 | + let timer = NSTimer.new(after: interval, block) | ||
| 35 | + timer.start() | ||
| 36 | + return timer | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + /// Create and schedule a timer that will call `block` repeatedly in specified time intervals. | ||
| 40 | + | ||
| 41 | + public class func every(interval: NSTimeInterval, _ block: () -> Void) -> NSTimer { | ||
| 42 | + let timer = NSTimer.new(every: interval, block) | ||
| 43 | + timer.start() | ||
| 44 | + return timer | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /// Create and schedule a timer that will call `block` repeatedly in specified time intervals. | ||
| 48 | + /// (This variant also passes the timer instance to the block) | ||
| 49 | + | ||
| 50 | + @nonobjc public class func every(interval: NSTimeInterval, _ block: NSTimer -> Void) -> NSTimer { | ||
| 51 | + let timer = NSTimer.new(every: interval, block) | ||
| 52 | + timer.start() | ||
| 53 | + return timer | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + // MARK: Create timers without scheduling | ||
| 57 | + | ||
| 28 | 58 | /// Create a timer that will call `block` once after the specified time. | |
| 29 | 59 | /// | |
| 30 | 60 | /// - Note: The timer won't fire until it's scheduled on the run loop. | |
@@ -40,7 +70,7 @@ extension NSTimer { | |||
| 40 | 70 | /// Create a timer that will call `block` repeatedly in specified time intervals. | |
| 41 | 71 | /// | |
| 42 | 72 | /// - Note: The timer won't fire until it's scheduled on the run loop. | |
| 43 | - /// Use `NSTimer.after` to create and schedule a timer in one step. | ||
| 73 | + /// Use `NSTimer.every` to create and schedule a timer in one step. | ||
| 44 | 74 | /// - Note: The `new` class function is a workaround for a crashing bug when using convenience initializers (rdar://18720947) | |
| 45 | 75 | ||
| 46 | 76 | public class func new(every interval: NSTimeInterval, _ block: () -> Void) -> NSTimer { | |
@@ -53,7 +83,7 @@ extension NSTimer { | |||
| 53 | 83 | /// (This variant also passes the timer instance to the block) | |
| 54 | 84 | /// | |
| 55 | 85 | /// - Note: The timer won't fire until it's scheduled on the run loop. | |
| 56 | - /// Use `NSTimer.after` to create and schedule a timer in one step. | ||
| 86 | + /// Use `NSTimer.every` to create and schedule a timer in one step. | ||
| 57 | 87 | /// - Note: The `new` class function is a workaround for a crashing bug when using convenience initializers (rdar://18720947) | |
| 58 | 88 | ||
| 59 | 89 | @nonobjc public class func new(every interval: NSTimeInterval, _ block: NSTimer -> Void) -> NSTimer { | |
@@ -63,31 +93,8 @@ extension NSTimer { | |||
| 63 | 93 | } | |
| 64 | 94 | return timer | |
| 65 | 95 | } | |
| 66 | - | ||
| 67 | - /// Create and schedule a timer that will call `block` once after the specified time. | ||
| 68 | - | ||
| 69 | - public class func after(interval: NSTimeInterval, _ block: () -> Void) -> NSTimer { | ||
| 70 | - let timer = NSTimer.new(after: interval, block) | ||
| 71 | - timer.start() | ||
| 72 | - return timer | ||
| 73 | - } | ||
| 74 | 96 | ||
| 75 | - /// Create and schedule a timer that will call `block` repeatedly in specified time intervals. | ||
| 76 | - | ||
| 77 | - public class func every(interval: NSTimeInterval, _ block: () -> Void) -> NSTimer { | ||
| 78 | - let timer = NSTimer.new(every: interval, block) | ||
| 79 | - timer.start() | ||
| 80 | - return timer | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - /// Create and schedule a timer that will call `block` repeatedly in specified time intervals. | ||
| 84 | - /// (This variant also passes the timer instance to the block) | ||
| 85 | - | ||
| 86 | - @nonobjc public class func every(interval: NSTimeInterval, _ block: NSTimer -> Void) -> NSTimer { | ||
| 87 | - let timer = NSTimer.new(every: interval, block) | ||
| 88 | - timer.start() | ||
| 89 | - return timer | ||
| 90 | - } | ||
| 97 | + // MARK: Manual scheduling | ||
| 91 | 98 | ||
| 92 | 99 | /// Schedule this timer on the run loop | |
| 93 | 100 | /// | |
| Back | FazBrowse Home | New Git URL |
0 commit comments