---
title: "countWords(in:language:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsspellchecker/countwords(in:language:)"
---

# countWords(in:language:)

Returns the number of words in the specified string.

## Declaration

```swift
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

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

## Discussion

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

## See Also

### Checking Strings for Spelling and Grammar

- [checkSpelling(of:startingAt:)](appkit/nsspellchecker/checkspelling(of:startingat:).md)
- [checkSpelling(of:startingAt:language:wrap:inSpellDocumentWithTag:wordCount:)](appkit/nsspellchecker/checkspelling(of:startingat:language:wrap:inspelldocumentwithtag:wordcount:).md)
- [checkGrammar(of:startingAt:language:wrap:inSpellDocumentWithTag:details:)](appkit/nsspellchecker/checkgrammar(of:startingat:language:wrap:inspelldocumentwithtag:details:).md)
- [check(_:range:types:options:inSpellDocumentWithTag:orthography:wordCount:)](appkit/nsspellchecker/check(_:range:types:options:inspelldocumentwithtag:orthography:wordcount:).md)
- [requestChecking(of:range:types:options:inSpellDocumentWithTag:completionHandler:)](appkit/nsspellchecker/requestchecking(of:range:types:options:inspelldocumentwithtag:completionhandler:).md)
- [guesses(forWordRange:in:language:inSpellDocumentWithTag:)](appkit/nsspellchecker/guesses(forwordrange:in:language:inspelldocumentwithtag:).md)
