---
title: "highPriorityGesture(_:including:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/highprioritygesture(_:including:)"
---

# highPriorityGesture(_:including:)

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

## Declaration

```swift
nonisolated func highPriorityGesture<T>(_ gesture: T, including mask: GestureMask = .all) -> some View where T : Gesture

```

## Parameters

- `gesture`: A gesture to attach to the view.
- `mask`: A value that controls how adding this gesture to the view affects other gestures recognized by the view and its subviews. Defaults to doc://com.apple.SwiftUI/documentation/SwiftUI/GestureMask/all.

## Discussion

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. Inside the VStack a red heart Image defines its own 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. struct HighPriorityGestureExample: View {     @State private var message = "Message"     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)         .frame(width: 200, height: 200)         .border(Color.purple)     } }

## See Also

### Defining custom gestures

- [highPriorityGesture(_:isEnabled:)](swiftui/view/highprioritygesture(_:isenabled:).md)
- [highPriorityGesture(_:name:isEnabled:)](swiftui/view/highprioritygesture(_:name:isenabled:).md)
- [handGestureShortcut(_:isEnabled:)](swiftui/view/handgestureshortcut(_:isenabled:).md)
- [defersSystemGestures(on:)](swiftui/view/deferssystemgestures(on:).md)
- [Gesture](swiftui/gesture.md)
- [AnyGesture](swiftui/anygesture.md)
- [HandActivationBehavior](swiftui/handactivationbehavior.md)
- [HandGestureShortcut](swiftui/handgestureshortcut.md)
