<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSTextContentStorage/textElement(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextContentStorage(im)textElementForAttributedString:"
  },
  "title" : "textElement(for:)"
}
-->

# textElement(for:)

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

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

## Parameters

`attributedString`

The attributed string to map into an [`NSTextElement`](/documentation/UIKit/NSTextElement).

## Return Value

An [`NSTextElement`](/documentation/UIKit/NSTextElement), or `nil`.

## Discussion

Returns `nil` when `attributedString` contains attributes not mappable to [`NSTextElement`](/documentation/UIKit/NSTextElement).

---

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)