<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/TapGesture",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI10TapGestureV"
  },
  "title" : "TapGesture"
}
-->

# TapGesture

A gesture that recognizes one or more taps.

```
nonisolated struct TapGesture
```

## Overview

To recognize a tap gesture on a view, create and configure the gesture, and
then add it to the view using the [`gesture(_:including:)`](/documentation/SwiftUI/View/gesture(_:including:)) modifier.
The following code adds a tap gesture to a [`Circle`](/documentation/SwiftUI/Circle) that toggles the color
of the circle:

```
struct TapGestureView: View {
    @State private var tapped = false

    var tap: some Gesture {
        TapGesture(count: 1)
            .onEnded { _ in self.tapped = !self.tapped }
    }

    var body: some View {
        Circle()
            .fill(self.tapped ? Color.blue : Color.red)
            .frame(width: 100, height: 100, alignment: .center)
            .gesture(tap)
    }
}
```

## Topics

### Creating a tap gesture

[`init(count:)`](/documentation/SwiftUI/TapGesture/init(count:))

Creates a tap gesture with the number of required taps.

[`init(count:inputKinds:)`](/documentation/SwiftUI/TapGesture/init(count:inputKinds:))

Creates a tap gesture with the number of required taps and the
input kinds the gesture recognizes.

[`count`](/documentation/SwiftUI/TapGesture/count)

The required number of tap events.

## Relationships

### Conforms To

[`Gesture`](/documentation/SwiftUI/Gesture)

---

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)