---
title: "archiveRootObject(_:toFile:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsarchiver/archiverootobject(_:tofile:)"
---

# archiveRootObject(_:toFile:)

Creates a temporary instance of NSArchiver and archives an object graph by encoding it into a data object and writing the resulting data object to a specified file.

## Declaration

```swift
class func archiveRootObject(_ rootObject: Any, toFile path: String) -> Bool
```

## Parameters

- `rootObject`: The root object of the object graph to archive.
- `path`: The location of the file into which to write the archive.

## Return Value

Return Value true if the archive was written successfully, otherwise false.

## Discussion

Discussion This convenience method invokes archivedData(withRootObject:) to get the encoded data, and then sends that data object the message write(toFile:atomically:), using path for the first argument and true for the second. The archived data should be retrieved from the archive by an NSUnarchiver object.

## See Also

### Related Documentation

- [write(toFile:atomically:)](foundation/nsdata/write(tofile:atomically:).md)

### Archiving data

- [archivedData(withRootObject:)](foundation/nsarchiver/archiveddata(withrootobject:).md)
- [encodeRootObject(_:)](foundation/nsarchiver/encoderootobject(_:).md)
- [encodeConditionalObject(_:)](foundation/nsarchiver/encodeconditionalobject(_:).md)
