---
title: "addGestureRecognizer(_:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsview/addgesturerecognizer(_:)"
---

# addGestureRecognizer(_:)

Attaches a gesture recognizer to the view.

## Declaration

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

## Parameters

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

## Discussion

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.

## See Also

### Managing Gesture Recognizers

- [gestureRecognizers](appkit/nsview/gesturerecognizers.md)
- [removeGestureRecognizer(_:)](appkit/nsview/removegesturerecognizer(_:).md)
