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

# NSTextPreview

A snapshot of the text in your view, which the system uses to create
user-visible effects.

```
@MainActor class NSTextPreview
```

## Overview

An `NSTextPreview` object provides a static image of your view’s text
content that the system can use to create animations. You provide preview
objects in response to system requests, such as ones from Writing Tools.
In addition to creating an image of your view’s text, you also specify
the location of that text in your view’s frame rectangle. When creating
animations, the system places the image on top of your view’s content
and animates changes to the image instead of to your view.

Create an `NSTextPreview` object in response to specific system requests.
Create an image with a transparent background and render your view’s text
into the image using the current text attributes. Construct your `NSTextPreview`
object with both the image and the frame rectangle that represents the
location of the rendered text in your view’s coordinate system. To highlight
specific portions of text, instead of all the text in the image, provide
a set of candidate rectangles with the locations of the text you want to highlight.

## Topics

### Creating a text preview

[`-  initWithSnapshotImage:presentationFrame:`](/documentation/AppKit/NSTextPreview/init(snapshotImage:presentationFrame:))

Creates a text preview using the specified image.

[`-  initWithSnapshotImage:presentationFrame:candidateRects:`](/documentation/AppKit/NSTextPreview/init(snapshotImage:presentationFrame:candidateRects:))

Creates a text preview using the specified image and rectangles that indicate
the portions of text to highlight.

### Getting the preview details

[`previewImage`](/documentation/AppKit/NSTextPreview/previewImage)

The image that contains the requested text from your view.

[`presentationFrame`](/documentation/AppKit/NSTextPreview/presentationFrame)

The frame rectangle that places the preview image directly over the
matching text.

[`candidateRects`](/documentation/AppKit/NSTextPreview/candidateRects)

Rectangles that define the specific portions of text to highlight.

## Relationships

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Sendable`](/documentation/Swift/Sendable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

---

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)