---
title: "perform(with:completionHandler:)"
framework: XcodeKit
role: symbol
role_heading: Instance Method
platforms: [macOS 10.12+]
path: "xcodekit/xcsourceeditorcommand/perform(with:completionhandler:)"
---

# perform(with:completionHandler:)

Performs the action associated with the command using the information in an invocation.

## Declaration

```swift
func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping @Sendable ((any Error)?) -> Void)
```

```swift
func perform(with invocation: XCSourceEditorCommandInvocation) async throws
```

## Parameters

- `invocation`: The invocation of the command to be invoked.
- `completionHandler`: A block to be executed when the command finishes.

## Mentioned in

Creating a Source Editor Extension Testing Your Source Editor Extension

## Discussion

Discussion Xcode passes the code a completion handler that it must invoke to finish performing the command, passing nil on success or an error on failure. A canceled command must still call the completion handler, passing nil. There are no guarantees about the thread or queue on which the cancellation handler is invoked.
