---
title: "write(toFile:atomically:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsdictionary/write(tofile:atomically:)"
---

# write(toFile:atomically:)

Writes a property list representation of the contents of the dictionary to a given path.

## Declaration

```swift
func write(toFile path: String, atomically useAuxiliaryFile: Bool) -> Bool
```

## Parameters

- `path`: The path at which to write the file. If path contains a tilde (~) character, you must expand it with doc://com.apple.foundation/documentation/Foundation/NSString/expandingTildeInPath before invoking this method.
- `useAuxiliaryFile`: A flag that specifies whether the file should be written atomically. If useAuxiliaryFile is doc://com.apple.documentation/documentation/Swift/true, the dictionary is written to an auxiliary file, and then the auxiliary file is renamed to path. If useAuxiliaryFile is doc://com.apple.documentation/documentation/Swift/false, the dictionary is written directly to path. The doc://com.apple.documentation/documentation/Swift/true option guarantees that path, if it exists at all, won’t be corrupted even if the system should crash during writing.

## Return Value

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

## Discussion

Discussion This method recursively validates that all the contained objects are property list objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary) before writing out the file, and returns false if all the objects are not property list objects, since the resultant file would not be a valid property list. If the dictionary’s contents are all property list objects, the file written by this method can be used to initialize a new dictionary with the class method dictionaryWithContentsOfFile: or the instance method init(contentsOfFile:). If you need greater control over the property list representation, use PropertyListSerialization instead. For more information about property lists, see Property List Programming Guide.

## See Also

### Storing Dictionaries

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