<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/highPriorityGesture(_:name:isEnabled:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE19highPriorityGesture_4name9isEnabledQrqd___SSSbtAA0F0Rd__lF"
  },
  "title" : "highPriorityGesture(_:name:isEnabled:)"
}
-->

# highPriorityGesture(_:name:isEnabled:)

Attaches a gesture to the view with a higher precedence than gestures
defined by the view.

```
nonisolated func highPriorityGesture<T>(_ gesture: T, name: String, isEnabled: Bool = true) -> some View where T : Gesture
```

## Parameters

`gesture`

A gesture to attach to the view.

`name`

A string that identifies the gesture. In iOS, the name can be
used to set up failure relationships between UIKit gesture
recognizers and this gesture.

`isEnabled`

Whether the added gesture is enabled. The default value
is `true`.

## Discussion

Use this method when you need to define a high priority gesture
to take precedence over the view’s existing gestures. The
example below defines a custom gesture that prints a message to the
console and attaches it to the view’s [`VStack`](/documentation/SwiftUI/VStack). Inside the [`VStack`](/documentation/SwiftUI/VStack)
a red heart [`Image`](/documentation/SwiftUI/Image) defines its own [`TapGesture`](/documentation/SwiftUI/TapGesture) handler that
also prints a message to the console, and a blue rectangle
with no custom gesture handlers. Tapping or clicking any of the
views results in a console message from the high priority gesture
attached to the enclosing [`VStack`](/documentation/SwiftUI/VStack).

You can also use the `isEnabled` parameter to conditionally disable
the gesture.

```
struct HighPriorityGestureExample: View {
    @State private var message = "Message"
    var isGestureEnabled: Bool
    let newGesture = TapGesture().onEnded {
        print("Tap on VStack.")
    }

    var body: some View {
        VStack(spacing:25) {
            Image(systemName: "heart.fill")
                .resizable()
                .frame(width: 75, height: 75)
                .padding()
                .foregroundColor(.red)
                .onTapGesture {
                    print("Tap on image.")
                }
            Rectangle()
                .fill(Color.blue)
        }
        .highPriorityGesture(
            newGesture, isEnabled: isGestureEnabled)
        .frame(width: 200, height: 200)
        .border(Color.purple)
    }
}
```

---

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)