<!--
{
  "availability" : [
    "macOS: 10.11.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSAlignmentFeedbackFilter",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAlignmentFeedbackFilter"
  },
  "title" : "NSAlignmentFeedbackFilter"
}
-->

# NSAlignmentFeedbackFilter

An object that can filter the movement of an object and provides haptic feedback when alignment occurs.

```
class NSAlignmentFeedbackFilter
```

## Overview

With a Force Touch trackpad, apps can produce tactile feedback to complement user actions. If your app implements alignment features, you can use the [`NSAlignmentFeedbackFilter`](/documentation/AppKit/NSAlignmentFeedbackFilter) class to filter object movements and provide haptic feedback to the user at appropriate times. As the user drags objects into alignment with a guide or another object, the user actually feels a physical bump as the object snaps into place.

### Implementing Alignment Feedback

To implement alignment feedback in your custom alignment controller class, set up the class to receive events for tracking the movement of an object. These can be events matching the [`inputEventMask`](/documentation/AppKit/NSAlignmentFeedbackFilter/inputEventMask) value of an `NSAlignmentFeedbackFilter` object, or events from a gesture recognizer ([`NSGestureRecognizer`](/documentation/AppKit/NSGestureRecognizer)). For each event received:

1. Create an instance of an `NSAlignmentFeedbackFilter` object. For example:

```swift
let self.feedbackFilter = NSAlignmentFeedbackFilter()
```

1. Inform the alignment feedback filter object about the event. To do this, call one of the following methods:

- [`update(with:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/update(with:))
- [`update(withPanRecognizer:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/update(withPanRecognizer:))

1. Store the location of the object before it moves in response to the event. This is considered the *previous* location of the object.
2. Move the object to its new location in response to the event. This is the location where the object will reside if no alignment occurs.
3. Store the new location of the object. This is considered the *default* location of the object.
4. Determine where the object will move to be aligned. This is considered the *aligned* location of the object.
5. Request a feedback token based on the previous location, default location, and aligned location. To do this, call one of the following methods:

- [`alignmentFeedbackTokenForMovement(in:previousPoint:alignedPoint:defaultPoint:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/alignmentFeedbackTokenForMovement(in:previousPoint:alignedPoint:defaultPoint:)) - If the object will be moved both horizontally and vertically to become aligned.
- [`alignmentFeedbackTokenForHorizontalMovement(in:previousX:alignedX:defaultX:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/alignmentFeedbackTokenForHorizontalMovement(in:previousX:alignedX:defaultX:)) - If the object will be moved horizontally only to become aligned.
- [`alignmentFeedbackTokenForVerticalMovement(in:previousY:alignedY:defaultY:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/alignmentFeedbackTokenForVerticalMovement(in:previousY:alignedY:defaultY:)) - If the object will be moved vertically only to become aligned.

1. If a feedback token is successfully prepared, call [`performFeedback(_:performanceTime:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/performFeedback(_:performanceTime:)) to perform the haptic feedback. Then, move the object to the aligned location.

If a value of `null` is returned, rather than a feedback token, then the system has determined that alignment and feedback are not appropriate. Perhaps the cursor is moving too fast or the distance to the aligned location is not significant enough to produce a visual snap. Move the object to its default location.

## Topics

### Determining Event Types for the Filter

[`inputEventMask`](/documentation/AppKit/NSAlignmentFeedbackFilter/inputEventMask)

Retrieves the event types the filter accepts.

### Informing the Filter About Events

[`update(with:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/update(with:))

Informs the feedback filter about a new event.

[`update(withPanRecognizer:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/update(withPanRecognizer:))

Informs the feedback filter about a new pan (drag) gesture recognizer event.

### Preparing Haptic Feedback for Alignment

[`alignmentFeedbackTokenForMovement(in:previousPoint:alignedPoint:defaultPoint:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/alignmentFeedbackTokenForMovement(in:previousPoint:alignedPoint:defaultPoint:))

Requests a feedback token for the alignment of an object requiring horizontal and vertical movement.

[`alignmentFeedbackTokenForHorizontalMovement(in:previousX:alignedX:defaultX:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/alignmentFeedbackTokenForHorizontalMovement(in:previousX:alignedX:defaultX:))

Requests a feedback token for the alignment of an object requiring horizontal movement only.

[`alignmentFeedbackTokenForVerticalMovement(in:previousY:alignedY:defaultY:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/alignmentFeedbackTokenForVerticalMovement(in:previousY:alignedY:defaultY:))

Requests a feedback token for the alignment of an object requiring vertical movement only.

### Providing Feedback to the User

[`performFeedback(_:performanceTime:)`](/documentation/AppKit/NSAlignmentFeedbackFilter/performFeedback(_:performanceTime:))

Performs the haptic feedback described by one or more alignment feedback tokens.



---

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)