<!--
{
  "availability" : [
    "iOS: 2.0.0 - 12.0.0",
    "iPadOS: 2.0.0 - 12.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.2.0 - 10.14.0",
    "tvOS: 9.0.0 - 12.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 5.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSKeyedArchiver/archiveRootObject(_:toFile:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSKeyedArchiver(cm)archiveRootObject:toFile:"
  },
  "title" : "archiveRootObject(_:toFile:)"
}
-->

# archiveRootObject(_:toFile:)

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

```
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

<doc://com.apple.documentation/documentation/Swift/true> if the operation was successful, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## 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`](/documentation/Foundation/PropertyListSerialization/PropertyListFormat/binary).

---

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)