Timer
extension Timer
-
Create and schedule a timer that will call
blockonce after the specified time.Declaration
Swift
@discardableResult public class func after(_ interval: TimeInterval, _ block: @escaping () -> Void) -> Timer -
Create and schedule a timer that will call
blockrepeatedly in specified time intervals.Declaration
Swift
@discardableResult public class func every(_ interval: TimeInterval, _ block: @escaping () -> Void) -> Timer -
Create and schedule a timer that will call
blockrepeatedly in specified time intervals. (This variant also passes the timer instance to the block)Declaration
Swift
@discardableResult public class func every(_ interval: TimeInterval, _ block: @escaping (Timer) -> Void) -> Timer
-
Create a timer that will call
blockonce after the specified time.Note
The timer won’t fire until it’s scheduled on the run loop. UseNSTimer.afterto create and schedule a timer in one step.Note
Thenewclass function is a workaround for a crashing bug when using convenience initializers (rdar://18720947)Declaration
Swift
public class func new(after interval: TimeInterval, _ block: @escaping () -> Void) -> Timer -
Create a timer that will call
blockrepeatedly in specified time intervals.Note
The timer won’t fire until it’s scheduled on the run loop. UseNSTimer.everyto create and schedule a timer in one step.Note
Thenewclass function is a workaround for a crashing bug when using convenience initializers (rdar://18720947)Declaration
Swift
public class func new(every interval: TimeInterval, _ block: @escaping () -> Void) -> Timer -
Create a timer that will call
blockrepeatedly in specified time intervals. (This variant also passes the timer instance to the block)Note
The timer won’t fire until it’s scheduled on the run loop. UseNSTimer.everyto create and schedule a timer in one step.Note
Thenewclass function is a workaround for a crashing bug when using convenience initializers (rdar://18720947)Declaration
Swift
public class func new(every interval: TimeInterval, _ block: @escaping (Timer) -> Void) -> Timer
-
Schedule this timer on the run loop
By default, the timer is scheduled on the current run loop for the default mode. Specify
runLoopormodesto override these defaults.Declaration
Swift
public func start(runLoop: RunLoop = .current, modes: RunLoop.Mode...)
View on GitHub
Timer Extension Reference