<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "ObjectiveC",
  "identifier" : "/documentation/ObjectiveC/NSObject-swift.class/perform(_:on:with:waitUntilDone:modes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Objective-C Runtime",
      "ObjectiveC"
    ],
    "preciseIdentifier" : "c:objc(cs)NSObject(im)performSelector:onThread:withObject:waitUntilDone:modes:"
  },
  "title" : "perform(_:on:with:waitUntilDone:modes:)"
}
-->

# perform(_:on:with:waitUntilDone:modes:)

Invokes a method of the receiver on the specified thread using the specified modes.

```
func perform(_ aSelector: Selector, on thr: Thread, with arg: Any?, waitUntilDone wait: Bool, modes array: [String]?)
```

## Parameters

`aSelector`

A [Selector](https://developer.apple.com/library/archive/documentation/General/Conceptual/DevPedia-CocoaCore/Selector.html#//apple_ref/doc/uid/TP40008195-CH48) that identifies the method to invoke. It should not have a significant return value and should take a single argument of type id, or no arguments.

`thr`

The thread on which to execute `aSelector`. This thread represents the target thread.

`arg`

The argument to pass to the method when it is invoked. Pass `nil` if the method does not take an argument.

`wait`

A Boolean that specifies whether the current thread blocks until after the specified selector is performed on the receiver on the specified thread. Specify [`YES`](/documentation/ObjectiveC/YES) to block this thread; otherwise, specify [`NO`](/documentation/ObjectiveC/NO) to have this method return immediately.

    If the current thread and target thread are the same, and you specify [`YES`](/documentation/ObjectiveC/YES)     for this parameter, the selector is performed immediately. If you specify [`NO`](/documentation/ObjectiveC/NO)    , this method queues the message and returns immediately, regardless of whether the threads are the same or different.

`array`

An array of strings that identifies the modes in which it is permissible to perform the specified selector. This array must contain at least one string. If you specify `nil` or an empty array for this parameter, this method returns without performing the specified selector. For information about run loop modes, see [Run Loops](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html#//apple_ref/doc/uid/10000057i-CH16) in [Threading Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html#//apple_ref/doc/uid/10000057i).

## Discussion

You can use this method to deliver messages to other threads in your application. The message in this case is a method of the current object that you want to execute on the target thread.

This method queues the message on the run loop of the target thread using the run loop modes specified in the `array` parameter. As part of its normal run loop processing, the target thread dequeues the message (assuming it is running in one of the specified modes) and invokes the desired method.

You cannot cancel messages queued using this method. If you want the option of canceling a message on the current thread, you must use either the [`perform(_:with:afterDelay:)`](/documentation/ObjectiveC/NSObject-swift.class/perform(_:with:afterDelay:)) or [`perform(_:with:afterDelay:inModes:)`](/documentation/ObjectiveC/NSObject-swift.class/perform(_:with:afterDelay:inModes:)) method instead.

### Special Considerations

This method registers with the runloop of its current context, and depends on that runloop being run on a regular basis to perform correctly. One common context where you might call this method and end up registering with a runloop that is not automatically run on a regular basis is when being invoked by a dispatch queue. If you need this type of functionality when running on a dispatch queue, you should use <doc://com.apple.documentation/documentation/Dispatch/dispatch_after> and related methods to get the behavior you want.

---

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)