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

# setSpellingState(_:range:)

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

```
func setSpellingState(_ value: Int, range charRange: NSRange)
```

## Parameters

`value`

The 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.

`charRange`

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

## Discussion

May be called or overridden to control setting of spelling and grammar indicators on text, used to highlight portions of the text that are flagged for spelling or grammar issues.

---

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)