<!--
{
  "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/Thread",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSThread"
  },
  "title" : "Thread"
}
-->

# Thread

A thread of execution.

```
class Thread
```

## Overview

Use this class when you want to have an Objective-C method run in its own thread of execution. Threads are especially useful when you need to perform a lengthy task, but don’t want it to block the execution of the rest of the application. In particular, you can use threads to avoid blocking the main thread of the application, which handles user interface and event-related actions. Threads can also be used to divide a large job into several smaller jobs, which can lead to performance increases on multi-core computers.

The [`Thread`](/documentation/Foundation/Thread) class supports semantics similar to those of [`Operation`](/documentation/Foundation/Operation) for monitoring the runtime condition of a thread. You can use these semantics to cancel the execution of a thread or determine if the thread is still executing or has finished its task. Canceling a thread requires support from your thread code; see the description for [`cancel()`](/documentation/Foundation/Thread/cancel()) for more information.

### Subclassing Notes

You can subclass [`Thread`](/documentation/Foundation/Thread) and override the [`main()`](/documentation/Foundation/Thread/main()) method to implement your thread’s main entry point. If you override [`main()`](/documentation/Foundation/Thread/main()), you do not need to invoke the inherited behavior by calling `super`.

## Topics

### Initializing an NSThread Object

[`init()`](/documentation/Foundation/Thread/init())

Returns an initialized `NSThread` object.

[`init(target:selector:object:)`](/documentation/Foundation/Thread/init(target:selector:object:))

Returns an `NSThread` object initialized with the given arguments.

### Starting a Thread

[`detachNewThreadSelector(_:toTarget:with:)`](/documentation/Foundation/Thread/detachNewThreadSelector(_:toTarget:with:))

Detaches a new thread and uses the specified selector as the thread entry point.

[`start()`](/documentation/Foundation/Thread/start())

Starts the receiver.

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

The main entry point routine for the thread.

### Stopping a Thread

[`sleep(until:)`](/documentation/Foundation/Thread/sleep(until:))

Blocks the current thread until the time specified.

[`sleep(forTimeInterval:)`](/documentation/Foundation/Thread/sleep(forTimeInterval:))

Sleeps the thread for a given time interval.

[`exit()`](/documentation/Foundation/Thread/exit())

Terminates the current thread.

[`cancel()`](/documentation/Foundation/Thread/cancel())

Changes the cancelled state of the receiver to indicate that it should exit.

### Determining the Thread’s Execution State

[`isExecuting`](/documentation/Foundation/Thread/isExecuting)

A Boolean value that indicates whether the receiver is executing.

[`isFinished`](/documentation/Foundation/Thread/isFinished)

A Boolean value that indicates whether the receiver has finished execution.

[`isCancelled`](/documentation/Foundation/Thread/isCancelled)

A Boolean value that indicates whether the receiver is cancelled.

### Working with the Main Thread

[`isMainThread`](/documentation/Foundation/Thread/isMainThread-swift.type.property)

Returns a Boolean value that indicates whether the current thread is the main thread.

[`isMainThread`](/documentation/Foundation/Thread/isMainThread-swift.property)

A Boolean value that indicates whether the receiver is the main thread.

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

Returns the `NSThread` object representing the main thread.

### Querying the Environment

[`isMultiThreaded()`](/documentation/Foundation/Thread/isMultiThreaded())

Returns whether the application is multithreaded.

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

Returns the thread object representing the current thread of execution.

[`callStackReturnAddresses`](/documentation/Foundation/Thread/callStackReturnAddresses)

Returns an array containing the call stack return addresses.

[`callStackSymbols`](/documentation/Foundation/Thread/callStackSymbols)

Returns an array containing the call stack symbols.

### Working with Thread Properties

[`threadDictionary`](/documentation/Foundation/Thread/threadDictionary)

The thread object’s dictionary.

[`NSAssertionHandlerKey`](/documentation/Foundation/NSAssertionHandlerKey)

A key with a corresponding value in the thread dictionary.

[`name`](/documentation/Foundation/Thread/name)

The name of the receiver.

[`stackSize`](/documentation/Foundation/Thread/stackSize)

The stack size of the receiver, in bytes.

### Prioritizing Thread Work

[`qualityOfService`](/documentation/Foundation/Thread/qualityOfService)

[`QualityOfService`](/documentation/Foundation/QualityOfService)

Constants that indicate the nature and importance of work to the system.

[`threadPriority()`](/documentation/Foundation/Thread/threadPriority())

Returns the current thread’s priority.

[`threadPriority`](/documentation/Foundation/Thread/threadPriority)

The receiver’s priority

[`setThreadPriority(_:)`](/documentation/Foundation/Thread/setThreadPriority(_:))

Sets the current thread’s priority.

### Notifications

[`NSDidBecomeSingleThreaded`](/documentation/Foundation/NSNotification/Name-swift.struct/NSDidBecomeSingleThreaded)

Not implemented.

[`NSThreadWillExit`](/documentation/Foundation/NSNotification/Name-swift.struct/NSThreadWillExit)

An `NSThread` object posts this notification when it receives the [`exit()`](/documentation/Foundation/Thread/exit()) message, before the thread exits. Observer methods invoked to receive this notification execute in the exiting thread, before it exits.

[`NSWillBecomeMultiThreaded`](/documentation/Foundation/NSNotification/Name-swift.struct/NSWillBecomeMultiThreaded)

Posted when the first thread is detached from the current thread. The `NSThread` class posts this notification at most once—the first time a thread is detached using [`detachNewThreadSelector(_:toTarget:with:)`](/documentation/Foundation/Thread/detachNewThreadSelector(_:toTarget:with:)) or the [`start()`](/documentation/Foundation/Thread/start()) method. Subsequent invocations of those methods do not post this notification. Observers of this notification have their notification method invoked in the main thread, not the new thread. The observer notification methods always execute before the new thread begins executing.



---

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)