<!--
{
  "availability" : [
    "macOS: 15.2.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSWritingToolsCoordinator/updateRange(_:with:reason:forContextWithIdentifier:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSWritingToolsCoordinator(im)updateRange:withText:reason:forContextWithIdentifier:"
  },
  "title" : "updateRange(_:with:reason:forContextWithIdentifier:)"
}
-->

# updateRange(_:with:reason:forContextWithIdentifier:)

Informs the coordinator about changes your app made to the text
in the specified context object.

```
func updateRange(_ range: NSRange, with replacementText: NSAttributedString, reason: NSWritingToolsCoordinator.TextUpdateReason, forContextWithIdentifier contextID: UUID)
```

## Parameters

`range`

The range of text to replace. This range is relative to
the starting location of the specified context object’s text in
your view’s text storage. If you initialized the context object
with the entire contents of your view’s text storage, specify the
range of text you’re replacing in your text storage. However, if
you initialized the context object with only a portion of your
view’s text, specify a range that is relative to the starting
location of the context object’s text.

`replacementText`

The text that replaces the previous content in
`range`. Specify an empty string to delete the text in the specified range.

`reason`

The reason you updated the text.

`contextID`

The unique identifier of the context object that
contains the text you modified.

## Discussion

If you make any changes to the text Writing Tools is evaluating, call
this method to report those changes to your view’s coordinator object.
You might make changes in response to an undo command or when someone
types into the same part of your view’s text. Calling this method
keeps the coordinator object informed of any changes, and ensures
it delivers accurate information to its delegate. In response, the
coordinator refreshes previews and other information related to your
view. If the scope of the update is significantly large, the coordinator
can optionally cancel the Writing Tools session altogether.

Use this method to report changes that precisely intersect your context
object’s text. The first time you call this method for a context object,
report changes only to the original attributed string in that object.
If you call this method more than once, report changes to the newly
modified version of that string. Don’t use this method to report changes
to text that comes before or after the context object. If you make
changes before your context object, report those changes separately using the
[`updateForReflowedTextInContextWithIdentifier(_:)`](/documentation/AppKit/NSWritingToolsCoordinator/updateForReflowedTextInContextWithIdentifier(_:)) method.

> Warning: Failure to call this method for a change can cause Writing Tools
> to deliver inaccurate information to your delegate and lead to data loss.

---

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)