2525import Foundation
2626
2727extension 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+
2858 /// Create a timer that will call `block` once after the specified time.
2959 ///
3060 /// - Note: The timer won't fire until it's scheduled on the run loop.
@@ -40,7 +70,7 @@ extension NSTimer {
4070 /// Create a timer that will call `block` repeatedly in specified time intervals.
4171 ///
4272 /// - 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.
4474 /// - Note: The `new` class function is a workaround for a crashing bug when using convenience initializers (rdar://18720947)
4575
4676 public class func new( every interval: NSTimeInterval , _ block: ( ) -> Void ) -> NSTimer {
@@ -53,7 +83,7 @@ extension NSTimer {
5383 /// (This variant also passes the timer instance to the block)
5484 ///
5585 /// - 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.
5787 /// - Note: The `new` class function is a workaround for a crashing bug when using convenience initializers (rdar://18720947)
5888
5989 @nonobjc public class func new( every interval: NSTimeInterval , _ block: NSTimer -> Void ) -> NSTimer {
@@ -63,31 +93,8 @@ extension NSTimer {
6393 }
6494 return timer
6595 }
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- }
7496
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
9198
9299 /// Schedule this timer on the run loop
93100 ///
0 commit comments