<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextViewDelegate/textView(_:shouldSetSpellingState:range:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextViewDelegate(im)textView:shouldSetSpellingState:range:"
  },
  "title" : "textView(_:shouldSetSpellingState:range:)"
}
-->

# textView(_:shouldSetSpellingState:range:)

Sent when the spelling state is changed.

```
@MainActor optional func textView(_ textView: NSTextView, shouldSetSpellingState value: Int, range affectedCharRange: NSRange) -> Int
```

## Parameters

`textView`

The text view sending the message.

`value`

The proposed spelling state value to set. Possible values, for the temporary attribute on the layout manager using the key NSSpellingStateAttributeName, are:

- [`NSSpellingStateSpellingFlag`](/documentation/AppKit/NSSpellingState/NSSpellingStateSpellingFlag) to highlight spelling issues.
- [`NSSpellingStateGrammarFlag`](/documentation/AppKit/NSSpellingState/NSSpellingStateGrammarFlag) to highlight grammar issues.

`affectedCharRange`

The character range over which to set the given spelling state.

## Return Value

The actual spelling state to set.

## Discussion

Delegate only. Allows delegate to control the setting of spelling and grammar indicators.

## See Also

[`-  setSpellingState:range:`](/documentation/AppKit/NSTextView/setSpellingState(_:range:))

Sets the spelling state, which controls the display of the spelling and grammar indicators on the given text range.



---

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)