---
title: "textLineFragment(for:isUpstreamAffinity:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/nstextlayoutfragment/textlinefragment(for:isupstreamaffinity:)"
---

# textLineFragment(for:isUpstreamAffinity:)

Returns a text line fragment from a specific text location in the document.

## Declaration

```swift
func textLineFragment(for textLocation: any NSTextLocation, isUpstreamAffinity: Bool) -> NSTextLineFragment?
```

## Parameters

- `textLocation`: A text location that a text line fragment contains.
- `isUpstreamAffinity`: A Boolean value that indicates whether the text line fragment ends at the text location you provide.

## Return Value

Return Value The text line fragment that contains or ends at the text location you provide, or nil if there isn’t a match.

## Discussion

Discussion Set isUpstreamAffinity to true to find a text fragment by its element range end location, such as when you enumerate over line fragments in reverse order. Set isUpstreamAffinity to false to find a text fragment that contains textLocation.

## See Also

### Getting line fragments

- [textLineFragments](uikit/nstextlayoutfragment/textlinefragments.md)
- [NSTextLayoutFragment.EnumerationOptions](uikit/nstextlayoutfragment/enumerationoptions.md)
- [textLineFragment(forVerticalOffset:requiresExactMatch:)](uikit/nstextlayoutfragment/textlinefragment(forverticaloffset:requiresexactmatch:).md)
