<!--
{
  "availability" : [
    "macOS: 10.12.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XcodeKit",
  "identifier" : "/documentation/XcodeKit/XCSourceEditorCommand/perform(with:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XcodeKit"
    ],
    "preciseIdentifier" : "c:objc(pl)XCSourceEditorCommand(im)performCommandWithInvocation:completionHandler:"
  },
  "title" : "perform(with:completionHandler:)"
}
-->

# perform(with:completionHandler:)

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

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

## Parameters

`invocation`

The invocation of the command to be invoked.

`completionHandler`

A block to be executed when the command finishes.

## 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.

---

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)