<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/gesture(_:including:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE7gesture_9includingQrqd___AA11GestureMaskVtAA0F0Rd__lF"
  },
  "title" : "gesture(_:including:)"
}
-->

# gesture(_:including:)

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

```
nonisolated func gesture<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 [`all`](/documentation/SwiftUI/GestureMask/all).

## Discussion

Use this method when you need to attach a gesture to a view. 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 blue rectangle
with no custom gesture handlers. Tapping or clicking the image
prints a message to the console from the tap gesture handler on the
image, while tapping or clicking  the rectangle inside the [`VStack`](/documentation/SwiftUI/VStack)
prints a message in the console from the enclosing vertical stack
gesture handler.

```
struct GestureExample: 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)
        }
        .gesture(newGesture)
        .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)