<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSSpellChecker/countWords(in:language:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSSpellChecker(im)countWordsInString:language:"
  },
  "title" : "countWords(in:language:)"
}
-->

# countWords(in:language:)

Returns the number of words in the specified string.

```
func countWords(in stringToCount: String, language: String?) -> Int
```

## Parameters

`stringToCount`

The string to count the words in.

`language`

The language of the string.

## Return Value

The number of words in the string or `-1` if word counting is unavailable or has not occurred for some reason.

## Discussion

If `language` is `nil`, the current selection in the Spelling panel’s pop-up menu is used.

---

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)