---
title: "textView(_:shouldChangeTextInRanges:replacementStrings:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextviewdelegate/textview(_:shouldchangetextinranges:replacementstrings:)"
---

# textView(_:shouldChangeTextInRanges:replacementStrings:)

Sent when a text view needs to determine if text in an array of specified ranges should be changed.

## Declaration

```swift
@MainActor optional func textView(_ textView: NSTextView, shouldChangeTextInRanges affectedRanges: [NSValue], replacementStrings: [String]?) -> Bool
```

## Parameters

- `textView`: The text view sending the message. This is the first text view in a series shared by a layout manager, not necessarily the text view displaying the selected text.
- `affectedRanges`: The array of ranges of characters to be replaced. This array must be a non-nil, non-empty array of objects responding to the NSValue rangeValue method, and in addition its elements must be sorted, non-overlapping, non-contiguous, and (except for the case of a single range) have non-zero-length.
- `replacementStrings`: The array of strings that will replace the characters in affectedRanges, one string for each range; nil if only text attributes are being changed.

## Return Value

Return Value true to allow the replacement, or false to reject the change.

## See Also

### Setting Text Attributes

- [textView(_:shouldChangeTextIn:replacementString:)](appkit/nstextviewdelegate/textview(_:shouldchangetextin:replacementstring:).md)
- [textView(_:shouldChangeTypingAttributes:toAttributes:)](appkit/nstextviewdelegate/textview(_:shouldchangetypingattributes:toattributes:).md)
- [textViewDidChangeTypingAttributes(_:)](appkit/nstextviewdelegate/textviewdidchangetypingattributes(_:).md)
