<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/RunLoop",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSRunLoop"
  },
  "title" : "RunLoop"
}
-->

# RunLoop

The programmatic interface to objects that manage input sources.

```
class RunLoop
```

## Overview

A [`RunLoop`](/documentation/Foundation/RunLoop) object processes input for sources, such as mouse and keyboard events from the window system and [`Port`](/documentation/Foundation/Port) objects. A [`RunLoop`](/documentation/Foundation/RunLoop) object also processes [`Timer`](/documentation/Foundation/Timer) events.

Your application neither creates nor explicitly manages [`RunLoop`](/documentation/Foundation/RunLoop) objects. The system creates a [`RunLoop`](/documentation/Foundation/RunLoop) object as needed for each [`Thread`](/documentation/Foundation/Thread) object, including the application’s main thread. If you need to access the current thread’s run loop, use the class method [`current`](/documentation/Foundation/RunLoop/current).

Note that from the perspective of [`RunLoop`](/documentation/Foundation/RunLoop), [`Timer`](/documentation/Foundation/Timer) objects aren’t “input”—they’re a special type, and they don’t cause the run loop to return when they fire.

> Warning:
> The ``doc://com.apple.foundation/documentation/Foundation/RunLoop`` class is generally not thread-safe, and you must call its methods only within the context of the current thread. Don’t call the methods of a ``doc://com.apple.foundation/documentation/Foundation/RunLoop`` object running in a different thread, which might cause unexpected results.

## Topics

### Accessing Run Loops and Modes

[`current`](/documentation/Foundation/RunLoop/current)

Returns the run loop for the current thread.

[`currentMode`](/documentation/Foundation/RunLoop/currentMode)

The receiver’s current input mode.

[`limitDate(forMode:)`](/documentation/Foundation/RunLoop/limitDate(forMode:))

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

[`main`](/documentation/Foundation/RunLoop/main)

Returns the run loop of the main thread.

[`getCFRunLoop()`](/documentation/Foundation/RunLoop/getCFRunLoop())

Returns the receiver’s underlying run loop object.

[`RunLoop.Mode`](/documentation/Foundation/RunLoop/Mode)

Modes that a run loop operates in.

### Managing Timers

[`add(_:forMode:)`](/documentation/Foundation/RunLoop/add(_:forMode:)-392ag)

Registers a given timer with a given input mode.

### Managing Ports

[`add(_:forMode:)`](/documentation/Foundation/RunLoop/add(_:forMode:)-6z982)

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

[`remove(_:forMode:)`](/documentation/Foundation/RunLoop/remove(_:forMode:))

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

### Configuring as Server Process

[`configureAsServer`](/documentation/Foundation/NSRunLoop/configureAsServer)

Deprecated. Does nothing.

### Running a Loop

[`run()`](/documentation/Foundation/RunLoop/run())

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

[`run(mode:before:)`](/documentation/Foundation/RunLoop/run(mode:before:))

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

[`run(until:)`](/documentation/Foundation/RunLoop/run(until:))

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

[`acceptInput(forMode:before:)`](/documentation/Foundation/RunLoop/acceptInput(forMode:before:))

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

### Scheduling and Canceling Tasks

[`perform(_:)`](/documentation/Foundation/RunLoop/perform(_:))

Schedules a block that the run loop invokes.

[`perform(inModes:block:)`](/documentation/Foundation/RunLoop/perform(inModes:block:))

Schedules a block that the run loop invokes when it’s running in any of the specified modes.

[`perform(_:target:argument:order:modes:)`](/documentation/Foundation/RunLoop/perform(_:target:argument:order:modes:))

Schedules the sending of a message on the receiver.

[`cancelPerform(_:target:argument:)`](/documentation/Foundation/RunLoop/cancelPerform(_:target:argument:))

Cancels the sending of a previously scheduled message.

[`cancelPerformSelectors(withTarget:)`](/documentation/Foundation/RunLoop/cancelPerformSelectors(withTarget:))

Cancels all outstanding ordered performs scheduled with a given target.

### Scheduling Combine Publishers

[`schedule(options:_:)`](/documentation/Foundation/RunLoop/schedule(options:_:))

Performs the action at some time after the specified date, using the scheduler’s minimum tolerance.

[`schedule(after:tolerance:options:_:)`](/documentation/Foundation/RunLoop/schedule(after:tolerance:options:_:))

Performs the action at some time after the specified date, using the specified tolerance and options.

[`schedule(after:interval:tolerance:options:_:)`](/documentation/Foundation/RunLoop/schedule(after:interval:tolerance:options:_:))

Performs the action at some time after the specified date, at the specified frequency, using the specified tolerance and options.

[`minimumTolerance`](/documentation/Foundation/RunLoop/minimumTolerance)

The minimum tolerance the run loop scheduler allows.

[`now`](/documentation/Foundation/RunLoop/now)

The run loop scheduler’s definition of the current moment in time.

[`RunLoop.SchedulerTimeType`](/documentation/Foundation/RunLoop/SchedulerTimeType)

The scheduler time type that the run loop uses.

[`RunLoop.SchedulerOptions`](/documentation/Foundation/RunLoop/SchedulerOptions)

A set of options that affect the operation of the run loop scheduler.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)