<!--
{
  "availability" : [
    "iOS: 2.0.0 - 2.0.0",
    "iPadOS: 2.0.0 - 2.0.0",
    "tvOS: 9.0.0 - 9.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSString/write(to:atomically:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)writeToURL:atomically:"
  },
  "title" : "write(to:atomically:)"
}
-->

# write(to:atomically:)

Writes the contents of the receiver to the location specified by a given URL.

```
func write(to url: URL, atomically: Bool) -> Bool
```

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the location is written successfully, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

If `atomically` is <doc://com.apple.documentation/documentation/Swift/true>, the receiver is written to an auxiliary location, and then the auxiliary location is renamed to `aURL`. If `atomically` is <doc://com.apple.documentation/documentation/Swift/false>, the receiver is written directly to `aURL`. The <doc://com.apple.documentation/documentation/Swift/true> option guarantees that `aURL`, if it exists at all, won’t be corrupted even if the system should crash during writing.

The `atomically` parameter is ignored if `aURL` is not of a type that can be accessed atomically.

## See Also

[`-  writeToURL:atomically:encoding:error:`](/documentation/Foundation/NSString/write(to:atomically:encoding:))

Writes the contents of the receiver to the URL specified by `url` using the specified encoding.



---

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)