<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/UIGestureRecognizerRepresentable",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI32UIGestureRecognizerRepresentableP"
  },
  "title" : "UIGestureRecognizerRepresentable"
}
-->

# UIGestureRecognizerRepresentable

A wrapper for a `UIGestureRecognizer` that you use to integrate that gesture
recognizer into your SwiftUI hierarchy.

```
@MainActor @preconcurrency protocol UIGestureRecognizerRepresentable
```

## Overview

Use a [`UIGestureRecognizerRepresentable`](/documentation/SwiftUI/UIGestureRecognizerRepresentable) instance to create and manage a
<doc://com.apple.documentation/documentation/UIKit/UIGestureRecognizer>
object in your SwiftUI interface.

To add your gesture recognizer to a SwiftUI view, create an instance of
[`UIGestureRecognizerRepresentable`](/documentation/SwiftUI/UIGestureRecognizerRepresentable) and use the [`gesture(_:)`](/documentation/SwiftUI/View/gesture(_:))
modifier to attach it. The system calls the methods of your representable
instance at appropriate times to create and update the gesture recognizer.

The following example shows the inclusion of a custom `MyGestureRecognizer`
structure in the view hierarchy.

```
struct ContentView: View {
   var body: some View {
      VStack {
         Image("Mountain").gesture(MyGestureRecognizer())
      }
   }
}
```

Because your [`UIGestureRecognizerRepresentable`](/documentation/SwiftUI/UIGestureRecognizerRepresentable) is a struct, it can
use the environment, have data dependencies, and is more similar to views in
SwiftUI. The system will call the appropriate methods on your instance to
propagate the latest data.

## Handling Gesture Recognizer Actions

SwiftUI automatically installs a target to handle the gesture recognizer’s
action on your behalf. Implement the `handleUIGestureRecognizerAction`
method to react to the gesture recognizing its action.

You can optionally include a coordinator object to forward delegate messages
from your gesture recognizer or add additional targets.

## Coordinate Space Conversions

The gesture recognizer you create may not be attached to a `UIView` in the
hierarchy, or it may return a view with different geometry than your SwiftUI
view.

To handle this, use the converter on the context to perform coordinate space
conversions from the global coordinate space. You can pass the gesture
recognizer and a SwiftUI coordinate space to the converter to retrieve a
final converted point. Passing the [`local`](/documentation/SwiftUI/CoordinateSpaceProtocol/local)
coordinate space (the default) will provide the point in the SwiftUI view
the gesture recognizer is attached to.

## Topics

### Associated Types

[`associatedtype Coordinator = Void`](/documentation/SwiftUI/UIGestureRecognizerRepresentable/Coordinator)

A type to coordinate with the gesture recognizer.

[`associatedtype UIGestureRecognizerType : UIGestureRecognizer`](/documentation/SwiftUI/UIGestureRecognizerRepresentable/UIGestureRecognizerType)

The type of `UIGestureRecognizer` to be presented.

### Instance Methods

[`func handleUIGestureRecognizerAction(Self.UIGestureRecognizerType, context: Self.Context)`](/documentation/SwiftUI/UIGestureRecognizerRepresentable/handleUIGestureRecognizerAction(_:context:))

Handles recognition of the represented `UIGestureRecognizer`.

[`func makeCoordinator(converter: Self.CoordinateSpaceConverter) -> Self.Coordinator`](/documentation/SwiftUI/UIGestureRecognizerRepresentable/makeCoordinator(converter:))

Creates the custom object that you use to communicate state changes from
your gesture recognizer to other parts of your SwiftUI interface.

[`func makeUIGestureRecognizer(context: Self.Context) -> Self.UIGestureRecognizerType`](/documentation/SwiftUI/UIGestureRecognizerRepresentable/makeUIGestureRecognizer(context:))

Creates an instance of the represented gesture recognizer.

[`func updateUIGestureRecognizer(Self.UIGestureRecognizerType, context: Self.Context)`](/documentation/SwiftUI/UIGestureRecognizerRepresentable/updateUIGestureRecognizer(_:context:))

Updates the `UIGestureRecognizer` (and coordinator) to the latest
configuration.

### Type Aliases

[`typealias Context`](/documentation/SwiftUI/UIGestureRecognizerRepresentable/Context)

Contextual information about the state of the system that you use to
create and update your gesture recognizer.

[`typealias CoordinateSpaceConverter`](/documentation/SwiftUI/UIGestureRecognizerRepresentable/CoordinateSpaceConverter)

A type used to convert coordinates to/from coordinate spaces in the
hierarchy of the associated SwiftUI view.

---

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)