<!--
{
  "availability" : [
    "macOS: 10.10.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSView/addGestureRecognizer(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSView(im)addGestureRecognizer:"
  },
  "title" : "addGestureRecognizer(_:)"
}
-->

# addGestureRecognizer(_:)

Attaches a gesture recognizer to the view.

```
func addGestureRecognizer(_ gestureRecognizer: NSGestureRecognizer)
```

## Parameters

`gestureRecognizer`

The gesture recognizer to attach to the view. This parameter must not be `nil`.

## Discussion

Attaching a gesture recognizer to a view defines the scope of the represented gesture, causing it to receive touches occurring only in the view or one of its subviews. The view establishes a strong reference to the specified gesture recognizer.

---

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)