---
title: "tokenRange(for:unit:)"
framework: naturallanguage
role: symbol
role_heading: Instance Method
path: "naturallanguage/nltagger/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.

## Declaration

```swift
@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 doc://com.apple.naturallanguage/documentation/NaturalLanguage/NLTokenUnit.

## Return Value

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

## See Also

### Determining the range of a unit token

- [tokenRange(at:unit:)](naturallanguage/nltagger/tokenrange(at:unit:).md)
- [NLTokenUnit](naturallanguage/nltokenunit.md)
