---
title: "textView(_:shouldSetSpellingState:range:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextviewdelegate/textview(_:shouldsetspellingstate:range:)"
---

# textView(_:shouldSetSpellingState:range:)

Sent when the spelling state is changed.

## Declaration

```swift
@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: doc://com.apple.appkit/documentation/AppKit/NSSpellingState/NSSpellingStateSpellingFlag to highlight spelling issues. doc://com.apple.appkit/documentation/AppKit/NSSpellingState/NSSpellingStateGrammarFlag to highlight grammar issues.
- `affectedCharRange`: The character range over which to set the given spelling state.

## Return Value

Return Value The actual spelling state to set.

## Discussion

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

## See Also

### Related Documentation

- [setSpellingState(_:range:)](appkit/nstextview/setspellingstate(_:range:).md)

### Working With the Spelling Checker

- [textView(_:willCheckTextIn:options:types:)](appkit/nstextviewdelegate/textview(_:willchecktextin:options:types:).md)
- [textView(_:didCheckTextIn:types:options:results:orthography:wordCount:)](appkit/nstextviewdelegate/textview(_:didchecktextin:types:options:results:orthography:wordcount:).md)
