---
title: "write(to:atomically:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/write(to:atomically:)"
---

# write(to:atomically:)

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

## Declaration

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

## Return Value

Return Value true if the location is written successfully, otherwise false.

## Discussion

Discussion If atomically is true, the receiver is written to an auxiliary location, and then the auxiliary location is renamed to aURL. If atomically is false, the receiver is written directly to aURL. The 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

### Related Documentation

- [write(to:atomically:encoding:)](foundation/nsstring/write(to:atomically:encoding:).md)

### Deprecated

- [string(withCString:)](foundation/nsstring/string(withcstring:).md)
- [init(CString:)](foundation/nsstring/init(cstring:)-vkuo.md)
- [string(withCString:length:)](foundation/nsstring/string(withcstring:length:).md)
- [init(CString:length:)](foundation/nsstring/init(cstring:length:)-5ure3.md)
- [init(CStringNoCopy:length:freeWhenDone:)](foundation/nsstring/init(cstringnocopy:length:freewhendone:)-86dm2.md)
- [string(withContentsOfFile:)](foundation/nsstring/string(withcontentsoffile:).md)
- [init(contentsOfFile:)](foundation/nsstring/init(contentsoffile:).md)
- [string(withContentsOf:)](foundation/nsstring/string(withcontentsof:).md)
- [init(contentsOfURL:)](foundation/nsstring/init(contentsofurl:).md)
- [write(toFile:atomically:)](foundation/nsstring/write(tofile:atomically:).md)
- [getCharacters(_:)](foundation/nsstring/getcharacters(_:).md)
- [cString()](foundation/nsstring/cstring().md)
- [lossyCString()](foundation/nsstring/lossycstring().md)
- [cStringLength()](foundation/nsstring/cstringlength().md)
- [getCString(_:)](foundation/nsstring/getcstring(_:).md)
