<!--
{
  "availability" : [
    "macOS: 10.0.0 -",
    "swift: -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAttributedString/init(RTF:documentAttributes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAttributedString(im)initWithRTF:documentAttributes:"
  },
  "title" : "init(RTF:documentAttributes:)"
}
-->

# init(RTF:documentAttributes:)

Creates an attributed string by decoding the stream of RTF commands and data in the specified data object.

```
init?(RTF data: Data, documentAttributes dict: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)
```

## Parameters

`data`

The data containing RTF content.

`dict`

An in-out dictionary containing document-level attributes. On output, this method updates the dictionary to contain any document-specific keys found in the data. Specify `nil` if you don’t want the document attributes.

## Return Value

Returns an initialized attributed string object, or `nil` if the method can’t decode the data.

## Discussion

Also returns by reference in `dict` a dictionary containing document-level attributes described in [`NSAttributedString.DocumentAttributeKey`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey). `dict` may be `NULL`, in which case no document attributes are returned. Returns an initialized object, or `nil` if `data` can’t be decoded.

---

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)