---
title: "textElement(for:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextcontentstorage/textelement(for:)"
---

# textElement(for:)

Returns the text element corresponding to object’s attributed string.

## Declaration

```swift
func textElement(for attributedString: NSAttributedString) -> NSTextElement?
```

## Parameters

- `attributedString`: The attributed string to map into an doc://com.apple.appkit/documentation/AppKit/NSTextElement.

## Return Value

Return Value An NSTextElement, or nil.

## Discussion

Discussion Returns nil when attributedString contains attributes not mappable to NSTextElement.

## See Also

### Managing text elements

- [attributedString(for:)](appkit/nstextcontentstorage/attributedstring(for:).md)
