<!--
{
  "availability" : [
    "macOS: 15.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/modifierKeyAlternate(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE20modifierKeyAlternateyQrAA14EventModifiersV_qd__yXEtAaBRd__lF"
  },
  "title" : "modifierKeyAlternate(_:_:)"
}
-->

# modifierKeyAlternate(_:_:)

Builds a view to use in place of the modified view when the user presses
the modifier key(s) indicated by the given set.

```
nonisolated func modifierKeyAlternate<V>(_ modifiers: EventModifiers, @ContentBuilder _ alternate: () -> V) -> some View where V : View
```

## Parameters

`modifiers`

The modifier keys to associate with the alternate view.
While all these keys are held, SwiftUI will replace the modified
view with this alternate one.

`alternate`

A content builder for constructing the modified view’s
alternate when matching modifier keys are pressed.

## Return Value

A modified view with an alternate view to use while specific
modifier keys are held down.

## Discussion

```
Button("Go Forward", ...)
    .modifierKeyAlternate(.option) {
        Button("Go to Page…", ...)
    }
```

In menu style contexts, modifier key alternates become alternate menu
items. If the modified view has a keyboard shortcut, it will be used as
the basis for the alternate view’s shortcut.

```
// File > Save
Button("Save", ...) // ⌘ S
    .keyboardShortcut("s")
    .modifierKeyAlternate(.option) {
        Button("Save All", ...) // ⌥⌘ S
    }
```

To use a different keyboard shortcut for the alternate view, add one
explicitly in the content builder. SwiftUI will use your explicit shortcut
instead of its own inferred one.

```
Button("Go Forward", ...) // ⌘ →
    .keyboardShortcut(.rightArrow)
    .modifierKeyAlternate(.control) {
        Button("Go To Page…", ...) // ⌃ →
            .keyboardShortcut(.rightArrow, modifiers: .control)
    }
```

A view can have multiple modifier key alternates, provided their
associated modifier keys are different. When multiple alternates match
the currently-held keys, the most specific match prevails.

```
Button("Save", ...) // ⌘ S
    .keyboardShortcut("s")
    .modifierKeyAlternate(.option) {
        Button("Save All", ...) // ⌥⌘ S
    }
    .modifierKeyAlternate([.option, .shift]) {
        Button("Save a Copy…", ...) // ⇧⌥⌘ S
    }
```

---

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)