<!--
{
  "documentType" : "article",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/identifying-parts-of-speech",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Identifying Parts of Speech"
}
-->

# Identifying Parts of Speech

Classify nouns, verbs, adjectives, and other parts of speech in a string.

## Discussion

Identifying the parts of speech for words in natural language text can help your program understand the meaning of sentences. For example, given the transcription of a request spoken by the user, you might determine general intent by looking at only the nouns and verbs.

The example below shows how to use [`NSLinguisticTagger`](/documentation/Foundation/NSLinguisticTagger) to enumerate over natural language text and identify the part of speech for each word.

```swift
let text = "The ripe taste of cheese improves with age."
let tagger = NSLinguisticTagger(tagSchemes: [.lexicalClass], options: 0)
tagger.string = text
let range = NSRange(location: 0, length: text.utf16.count)
let options: NSLinguisticTagger.Options = [.omitPunctuation, .omitWhitespace]
tagger.enumerateTags(in: range, unit: .word, scheme: .lexicalClass, options: options) { tag, tokenRange, _ in
    if let tag = tag {
        let word = (text as NSString).substring(with: tokenRange)
        print("\(word): \(tag)")
    }
}
```

First, an instance of [`NSLinguisticTagger`](/documentation/Foundation/NSLinguisticTagger) is created, specifying [`lexicalClass`](/documentation/Foundation/NSLinguisticTagScheme/lexicalClass) as the tag scheme to be used. Next, the [`string`](/documentation/Foundation/NSLinguisticTagger/string) property of the linguistic tagger is set to the natural language text. Finally, the linguistic tagger enumerates over the entire range of the string, specifying [`NSLinguisticTaggerUnit.word`](/documentation/Foundation/NSLinguisticTaggerUnit/word) as the tag unit and [`lexicalClass`](/documentation/Foundation/NSLinguisticTagScheme/lexicalClass) as the tag scheme, and omitting any punctuation or whitespace. In the enumeration block, the part of speech is provided by `tag`, and each word is obtained by taking a substring of the original text at `tokenRange`.

When run, this code prints out each word and its part of speech on a new line, as shown below:

|Word    |Part of speech                                                                     |
|--------|-----------------------------------------------------------------------------------|
|The     |``doc://com.apple.foundation/documentation/Foundation/NSLinguisticTag/determiner`` |
|ripe    |``doc://com.apple.foundation/documentation/Foundation/NSLinguisticTag/adjective``  |
|taste   |``doc://com.apple.foundation/documentation/Foundation/NSLinguisticTag/noun``       |
|of      |``doc://com.apple.foundation/documentation/Foundation/NSLinguisticTag/preposition``|
|cheese  |``doc://com.apple.foundation/documentation/Foundation/NSLinguisticTag/noun``       |
|improves|``doc://com.apple.foundation/documentation/Foundation/NSLinguisticTag/verb``       |
|with    |``doc://com.apple.foundation/documentation/Foundation/NSLinguisticTag/preposition``|
|age     |``doc://com.apple.foundation/documentation/Foundation/NSLinguisticTag/noun``       |

## See Also

[Tokenizing Natural Language Text](/documentation/Foundation/tokenizing-natural-language-text)

Enumerate the words in a string.



---

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)