---
title: "textView(_:shouldChangeTextIn:replacementString:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextviewdelegate/textview(_:shouldchangetextin:replacementstring:)"
---

# textView(_:shouldChangeTextIn:replacementString:)

Sent when a text view needs to determine if text in a specified range should be changed.

## Declaration

```swift
@MainActor optional func textView(_ textView: NSTextView, shouldChangeTextIn affectedCharRange: NSRange, replacementString: 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.
- `affectedCharRange`: The range of characters to be replaced.
- `replacementString`: The characters that will replace the characters in affectedCharRange; nil if only text attributes are being changed.

## Return Value

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

## Discussion

Discussion If a delegate implements this method and not its multiple-selection replacement, textView(_:shouldChangeTextInRanges:replacementStrings:), it is called with an appropriate range and string. If a delegate implements the new method, then this one is ignored.

## See Also

### Setting Text Attributes

- [textView(_:shouldChangeTextInRanges:replacementStrings:)](appkit/nstextviewdelegate/textview(_:shouldchangetextinranges:replacementstrings:).md)
- [textView(_:shouldChangeTypingAttributes:toAttributes:)](appkit/nstextviewdelegate/textview(_:shouldchangetypingattributes:toattributes:).md)
- [textViewDidChangeTypingAttributes(_:)](appkit/nstextviewdelegate/textviewdidchangetypingattributes(_:).md)
