Class

RunLoop

The programmatic interface to objects that manage input sources.

Overview

A RunLoop object processes input for sources such as mouse and keyboard events from the window system, Port objects, and NSConnection objects. A RunLoop object also processes Timer events.

Your application neither creates or explicitly manages RunLoop objects. Each Thread object—including the application’s main thread—has an RunLoop object automatically created for it as needed. If you need to access the current thread’s run loop, you do so with the class method current.

Note that from the perspective of RunLoop, Timer objects are not "input"—they are a special type, and one of the things that means is that they do not cause the run loop to return when they fire.

Topics

Accessing Run Loops and Modes

var currentMode: RunLoopMode?

The receiver's current input mode.

func limitDate(forMode: RunLoopMode)

Performs one pass through the run loop in the specified mode and returns the date at which the next timer is scheduled to fire.

class var main: RunLoop

Returns the run loop of the main thread.

func getCFRunLoop()

Returns the receiver's underlying CFRunLoop object.

Managing Timers

func add(Timer, forMode: RunLoopMode)

Registers a given timer with a given input mode.

Managing Ports

func add(Port, forMode: RunLoopMode)

Adds a port as an input source to the specified mode of the run loop.

func remove(Port, forMode: RunLoopMode)

Removes a port from the specified input mode of the run loop.

Running a Loop

func run()

Puts the receiver into a permanent loop, during which time it processes data from all attached input sources.

func run(mode: RunLoopMode, before: Date)

Runs the loop once, blocking for input in the specified mode until a given date.

func run(until: Date)

Runs the loop until the specified date, during which time it processes data from all attached input sources.

func acceptInput(forMode: RunLoopMode, before: Date)

Runs the loop once or until the specified date, accepting input only for the specified mode.

Scheduling and Canceling Messages

func cancelPerform(Selector, target: Any, argument: Any?)

Cancels the sending of a previously scheduled message.

func cancelPerformSelectors(withTarget: Any)

Cancels all outstanding ordered performs scheduled with a given target.

Constants

Run Loop Modes

NSRunLoop defines the following run loop mode.

Relationships

Inherits From

Conforms To

See Also

Run Loop Scheduling

class Timer

A timer that fires after a time interval has elapsed, sending a specified message to a target object.