<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSText/writeRTFD(toFile:atomically:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSText(im)writeRTFDToFile:atomically:"
  },
  "title" : "writeRTFD(toFile:atomically:)"
}
-->

# writeRTFD(toFile:atomically:)

Writes the receiver’s text as RTF with attachments to a file or directory at `path`.

```
func writeRTFD(toFile path: String, atomically flag: Bool) -> Bool
```

## Discussion

Returns <doc://com.apple.documentation/documentation/Swift/true> on success and <doc://com.apple.documentation/documentation/Swift/false> on failure. If `atomicFlag` is <doc://com.apple.documentation/documentation/Swift/true>, attempts to write the file safely so that an existing file at `path` is not overwritten, nor does a new file at `path` actually get created, unless the write is successful.

---

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)