<!--
{
  "availability" : [
    "macOS: 10.10.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSGestureRecognizer/init(target:action:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSGestureRecognizer(im)initWithTarget:action:"
  },
  "title" : "init(target:action:)"
}
-->

# init(target:action:)

Initializes the gesture recognizer with the specified target and action information.

```
init(target: Any?, action: Selector?)
```

## Parameters

`target`

The object whose action method is called when the gesture is recognized. You must not specify `nil` for this parameter.

`action`

A selector that identifies the method to call when the gesture is recognized. This method must be implemented by the object in `target`. You must not specify `nil` for this parameter.

## Return Value

The initialized gesture recognizer object or `nil` if an error occurred.

## Discussion

This method is the designated initializer. Subclasses must call this method from their own custom initialization methods. Call the method before performing other tasks.

This method records the specified `target` and `action` values and prepares the gesture recognizer for use.

The `action` method must have one of the following signatures:

```objc
- (void)handleGesture;
- (void)handleGesture:(NSGestureRecognizer *)gestureRecognizer;
```

## See Also

[`target`](/documentation/AppKit/NSGestureRecognizer/target)

The object that implements the action method.

[`NSGestureRecognizer`](/documentation/AppKit/NSGestureRecognizer)

An object that monitors events and calls its action method when a predefined sequence of events occur.

[`action`](/documentation/AppKit/NSGestureRecognizer/action)

The action method to call when the gesture is recognized.



---

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)