<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextView/shouldChangeText(inRanges:replacementStrings:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextView(im)shouldChangeTextInRanges:replacementStrings:"
  },
  "title" : "shouldChangeText(inRanges:replacementStrings:)"
}
-->

# shouldChangeText(inRanges:replacementStrings:)

Initiates a series of delegate messages (and general notifications) to determine whether modifications can be made to the characters and attributes of the receiver’s text.

```
func shouldChangeText(inRanges affectedRanges: [NSValue], replacementStrings: [String]?) -> Bool
```

## Parameters

`affectedRanges`

An array of ranges to change.

`replacementStrings`

An array of strings containing the characters that replace those in `affectedRanges`, one for each range. If only text attributes are being changed, `replacementStrings` is `nil`.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> to allow the change, <doc://com.apple.documentation/documentation/Swift/false> to prohibit it.

## Discussion

This method checks with the delegate as needed using [`textShouldBeginEditing(_:)`](/documentation/AppKit/NSTextDelegate/textShouldBeginEditing(_:)) and [`textView(_:shouldChangeTextInRanges:replacementStrings:)`](/documentation/AppKit/NSTextViewDelegate/textView(_:shouldChangeTextInRanges:replacementStrings:)).

This method must be invoked at the start of any sequence of user-initiated editing changes. If your subclass of `NSTextView` implements

that modify the text, make sure to invoke this method to determine whether the change should be made. If the change is allowed, complete the change by invoking the [`didChangeText()`](/documentation/AppKit/NSTextView/didChangeText()) method. If you can’t determine the affected range or replacement string before beginning changes, pass `nil` for these values.

### Special Considerations

If you override this method, you must call `super` at the beginning of the override.

If the receiver is not editable, this method automatically returns <doc://com.apple.documentation/documentation/Swift/false>. This result prevents instances in which a text view could be changed by user actions even though it had been set to be non-editable.

## See Also

[`editable`](/documentation/AppKit/NSTextView/isEditable)

A Boolean value that controls whether the text views sharing the receiver’s layout manager allow the user to edit text.



---

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)