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

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

Asks the delegate to divide the specified range of text into the separate
containers that render that text.

```
optional func writingToolsCoordinator(_ writingToolsCoordinator: NSWritingToolsCoordinator, requestsSingleContainerSubrangesOf range: NSRange, in context: NSWritingToolsCoordinator.Context, completion: @escaping @Sendable ([NSValue]) -> Void)
```

```
optional func writingToolsCoordinator(_ writingToolsCoordinator: NSWritingToolsCoordinator, singleContainerSubrangesOf range: NSRange, in context: NSWritingToolsCoordinator.Context) async -> [NSValue]
```

## Parameters

`writingToolsCoordinator`

The coordinator object requesting information
from your custom view.

`range`

The range of text to consider in the specified `context` object.
The location value of this range is relative to the beginning of the text
in your context object, and it’s your responsibility to match that location
to the correct location in your text storage. If you initialized the
context object with the entire contents of your view’s text storage,
you can use `range` as-is to access that text storage. However, if you
initialized the context object with only a portion of your view’s text,
add the starting location of your context object’s text to this value
to get the correct range for that text storage.

`context`

The context object that contains the text to consider. Use this
object to locate the appropriate text storage object for your view.

`completion`

A completion handler to execute when you are done. The handler
has no return value and takes an array of <doc://com.apple.documentation/documentation/Foundation/NSValue>
types, each of which contains an <doc://com.apple.documentation/documentation/Foundation/NSRange-c.struct>.
The union of the ranges you pass to this handler must equal all of the
text in `range`. The order of the ranges in the array must be sequential,
with each new range’s starting location coming after the previous one.
There must also not be any gaps or overlap between ranges.
You must call this handler at some point during your implementation.

## Discussion

If your view uses multiple [`NSTextContainer`](/documentation/AppKit/NSTextContainer) objects to draw text in different
regions, use this method to tell Writing Tools about the containers that display
the specified text. In your implementation, subdivide `range` to create one new
range for each portion of text that resides in a different container object.
For example, if the text in `range` is split between two containers, provide
two new <doc://com.apple.documentation/documentation/Foundation/NSRange-c.struct> types
that reflect the portion of the total text in each container. If `range` resides completely
within one container, call the completion handler with `range` as the only value
in the array.

When configuring animations for your view, Writing Tools asks your delegate to
provide separate previews for each of your view’s container object. Specifically,
it calls your delegate’s [`writingToolsCoordinator(_:requestsPreviewFor:of:in:completion:)`](/documentation/AppKit/NSWritingToolsCoordinator/Delegate-swift.protocol/writingToolsCoordinator(_:requestsPreviewFor:of:in:completion:))
method separately for each range of text you return in the completion handler.
Your implementation of that method must create a preview suitable for animating
the content from the underlying text container.

---

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)