<!--
{
  "availability" : [
    "macOS: 15.2.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSWritingToolsCoordinator/Delegate-swift.protocol/writingToolsCoordinator(_:requestsPreviewFor:in:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSWritingToolsCoordinatorDelegate(im)writingToolsCoordinator:requestsPreviewForRect:inContext:completion:"
  },
  "title" : "writingToolsCoordinator(_:requestsPreviewFor:in:completion:)"
}
-->

# writingToolsCoordinator(_:requestsPreviewFor:in:completion:)

Asks the delegate for a preview image and layout information for the
specified text.

```
func writingToolsCoordinator(_ writingToolsCoordinator: NSWritingToolsCoordinator, requestsPreviewFor rect: NSRect, in context: NSWritingToolsCoordinator.Context, completion: @escaping @Sendable (NSTextPreview?) -> Void)
```

```
func writingToolsCoordinator(_ writingToolsCoordinator: NSWritingToolsCoordinator, previewFor rect: NSRect, context: NSWritingToolsCoordinator.Context) async -> NSTextPreview?
```

## Parameters

`writingToolsCoordinator`

The coordinator object notifying you that
animations are about to begin.

`rect`

The portion of your view that contains the requested text. This rectangle is in the view’s coordinate system.

`context`

The context object that contains the original text. Use this
object to fetch the current text, and to match that text to your
underlying text storage.

`completion`

A completion handler to execute when you are done. The
handler has no return value and takes an [`NSTextPreview`](/documentation/AppKit/NSTextPreview) object
as a parameter. You must call this handler at some point during your implementation.

## Discussion

During an interactive evaluation of your view’s text, Writing Tools creates
different animations to provide feedback on what’s happening. As part of
the preparation for those animations, Writing Tools asks you to provide
a preview of the affected content in your view. Writing Tools uses this
preview to build and execute the animations in the view stored in the
[`effectContainerView`](/documentation/AppKit/NSWritingToolsCoordinator/effectContainerView) property of the coordinator object.

To build a preview of your content in macOS, render the requested portion
of your view into an image with a transparent background and use that image
to create your [`NSTextPreview`](/documentation/AppKit/NSTextPreview) object directly. Set the [`presentationFrame`](/documentation/AppKit/NSTextPreview/presentationFrame)
property to the specified rectangle. Set the [`candidateRects`](/documentation/AppKit/NSTextPreview/candidateRects)
property to an array containing one rectangle per line of the associated
text, which you get from your view’s layout manager.

> Important: Provide one rectangle per line in `candidateRects`. Writing
> Tools uses each rectangle to animate its line independently, producing a
> bounce effect. If you provide a single rectangle that spans the entire
> range instead, Writing Tools can only animate the text as one unit, which
> produces a shimmer instead of a bounce.

For a single animation type, the system calls the
[`writingToolsCoordinator(_:prepareFor:for:in:completion:)`](/documentation/AppKit/NSWritingToolsCoordinator/Delegate-swift.protocol/writingToolsCoordinator(_:prepareFor:for:in:completion:))
method, followed sequentially by this method and then the
[`writingToolsCoordinator(_:finish:for:in:completion:)`](/documentation/AppKit/NSWritingToolsCoordinator/Delegate-swift.protocol/writingToolsCoordinator(_:finish:for:in:completion:))
method. Each method executes asynchronously, but the system calls the next
method in the sequence only after you call the completion handler of the
previous method. However, multiple animations can run simultaneously, so
check the `textAnimation` parameter to differentiate sequences.

---

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)