<!--
{
  "availability" : [
    "iOS: 3.2.0 -",
    "iPadOS: 3.2.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextInputTokenizer/isPosition(_:withinTextUnit:inDirection:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextInputTokenizer(im)isPosition:withinTextUnit:inDirection:"
  },
  "title" : "isPosition(_:withinTextUnit:inDirection:)"
}
-->

# isPosition(_:withinTextUnit:inDirection:)

Return whether a text position is within a text unit of a specified granularity in a specified direction.

```
func isPosition(_ position: UITextPosition, withinTextUnit granularity: UITextGranularity, inDirection direction: UITextDirection) -> Bool
```

## Parameters

`position`

A text-position object that represents a location in a document.

`granularity`

A constant that indicates a certain granularity of text unit.

`direction`

A constant that indicates a direction relative to `position`. The constant can be of type UITextStorageDirection or UITextLayoutDirection.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the text position is within a text unit of the specified granularity in the specified direction; otherwise, return <doc://com.apple.documentation/documentation/Swift/false>. If the text position is *at* a boundary, return <doc://com.apple.documentation/documentation/Swift/true> only if the boundary is part of the text unit in the given direction.

## Discussion

---

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)