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

# archiveRootObject(_:toFile:)

Archives an object graph rooted at a given object to a file at a given path.

## Declaration

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

## Parameters

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

## Return Value

Return Value true if the operation was successful, otherwise false.

## Discussion

Discussion This method archives the graph formed by the root object to a data object, then atomically writes it to the given path. The format of the archive is PropertyListSerialization.PropertyListFormat.binary.

## See Also

### Archiving Data

- [archivedData(withRootObject:requiringSecureCoding:)](foundation/nskeyedarchiver/archiveddata(withrootobject:requiringsecurecoding:).md)
- [finishEncoding()](foundation/nskeyedarchiver/finishencoding().md)
- [encodedData](foundation/nskeyedarchiver/encodeddata.md)
- [outputFormat](foundation/nskeyedarchiver/outputformat.md)
- [requiresSecureCoding](foundation/nskeyedarchiver/requiressecurecoding.md)
- [archivedData(withRootObject:)](foundation/nskeyedarchiver/archiveddata(withrootobject:).md)
