<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTestCase/addUIInterruptionMonitor(withDescription:handler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTestCase(im)addUIInterruptionMonitorWithDescription:handler:"
  },
  "title" : "addUIInterruptionMonitor(withDescription:handler:)"
}
-->

# addUIInterruptionMonitor(withDescription:handler:)

Adds a handler to the current context.

```
func addUIInterruptionMonitor(withDescription handlerDescription: String, handler: @escaping (XCUIElement) -> Bool) -> any NSObjectProtocol
```

## Parameters

`handlerDescription`

An explanation of the behavior and purpose of this handler, mainly used for debugging and analysis.

`handler`

A handler block for handling asynchronous UI interruptions such as alerts and other dialogs. Handlers should return <doc://com.apple.documentation/documentation/Swift/true> if they handled the UI, <doc://com.apple.documentation/documentation/Swift/false> if they did not. The handler is passed an <doc://com.apple.documentation/documentation/XCUIAutomation/XCUIElement> representing the top level UI element for the alert.

## Return Value

Returns a token that can be used to unregister the handler. Handlers are invoked in the reverse order in which they are added until one of the handlers returns true, indicating that it has handled the alert.

## Discussion

---

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)