<!--
{
  "availability" : [
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/onExitCommand(perform:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE13onExitCommand7performQryycSg_tF"
  },
  "title" : "onExitCommand(perform:)"
}
-->

# onExitCommand(perform:)

Sets up an action that triggers in response to receiving the exit
command while the view has focus.

```
nonisolated func onExitCommand(perform action: (() -> Void)?) -> some View
```

## Discussion

The user generates an exit command by pressing the Menu button on tvOS,
or the escape key on macOS.

---

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)