<!--
{
  "availability" : [
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAttributedString/rtfdFileWrapper(from:documentAttributes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAttributedString(im)RTFDFileWrapperFromRange:documentAttributes:"
  },
  "title" : "rtfdFileWrapper(from:documentAttributes:)"
}
-->

# rtfdFileWrapper(from:documentAttributes:)

Returns a file wrapper object that contains an RTFD document corresponding to the characters and attributes within the specified range.

```
func rtfdFileWrapper(from range: NSRange, documentAttributes dict: [NSAttributedString.DocumentAttributeKey : Any] = [:]) -> FileWrapper?
```

## Parameters

`range`

The range.

`dict`

A required dictionary specifying the document attributes. The dictionary contains values from `Document Types` and must at least contain `NSDocumentTypeDocumentAttribute`.

## Return Value

A file wrapper containing the RTFD data.

## Discussion

The file wrapper also includes the document-level attributes in `docAttributes`, as explained in [RTF Files and Attributed Strings](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/TextAttributes/RTFAndAttrStrings.html#//apple_ref/doc/uid/20000164).

Raises an [`rangeException`](/documentation/Foundation/NSExceptionName/rangeException) if any part of `aRange` lies beyond the end of the receiver’s characters.

You can save the file wrapper using the [`write(toFile:atomically:updateFilenames:)`](/documentation/Foundation/FileWrapper/write(toFile:atomically:updateFilenames:)) method of [`FileWrapper`](/documentation/Foundation/FileWrapper).

---

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)