<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "NaturalLanguage",
  "identifier" : "/documentation/NaturalLanguage/NLTagger/tokenRange(for:unit:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Natural Language",
      "NaturalLanguage"
    ],
    "preciseIdentifier" : "s:So8NLTaggerC15NaturalLanguageE10tokenRange3for4unitSnySS5IndexVGAI_So11NLTokenUnitVtF"
  },
  "title" : "tokenRange(for:unit:)"
}
-->

# tokenRange(for:unit:)

Finds the entire range of all tokens of the specified linguistic unit contained completely or partially within the specified range.

```
@nonobjc func tokenRange(for range: Range<String.Index>, unit: NLTokenUnit) -> Range<String.Index>
```

## Parameters

`range`

The range within the string to search for tokens.

`unit`

The linguistic unit. For possible values, see [`NLTokenUnit`](/documentation/NaturalLanguage/NLTokenUnit).

## Return Value

The smallest possible range that contains all of the tokens of the specified linguistic unit within the range specified in `range`. This result includes a token’s entire range if any part of that token is included within `range`. If the length of `range` is 0, this return value is equivalent to [`tokenRangeAtIndex:unit:`](/documentation/NaturalLanguage/NLTagger/tokenRangeAtIndex:unit:).

---

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)