<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextContentStorage/attributedString(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextContentStorage(im)attributedStringForTextElement:"
  },
  "title" : "attributedString(for:)"
}
-->

# attributedString(for:)

Returns a new attributed string for the text element.

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

## Parameters

`textElement`

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

## Return Value

An <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>, or `nil`.

## Discussion

Returns `nil` if the method can’t map `textElement` to an <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>.

---

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)