---
title: "addUIInterruptionMonitor(withDescription:handler:)"
framework: xctest
role: symbol
role_heading: Instance Method
path: "xctest/xctestcase/adduiinterruptionmonitor(withdescription:handler:)"
---

# addUIInterruptionMonitor(withDescription:handler:)

Adds a handler to the current context.

## Declaration

```swift
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.

## Mentioned in

Handling UI Interruptions

## Return Value

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.

## See Also

### Monitoring UI Interruptions

- [Handling UI Interruptions](xctest/handling-ui-interruptions.md)
- [removeUIInterruptionMonitor(_:)](xctest/xctestcase/removeuiinterruptionmonitor(_:).md)
