<!--
{
  "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/NSKeyedUnarchiver/unarchiveObject(withFile:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSKeyedUnarchiver(cm)unarchiveObjectWithFile:"
  },
  "title" : "unarchiveObject(withFile:)"
}
-->

# unarchiveObject(withFile:)

Decodes and returns the object graph previously encoded by `NSKeyedArchiver` written to the file at a given path.

```
class func unarchiveObject(withFile path: String) -> Any?
```

## Parameters

`path`

A path to a file that contains an object graph previously encoded by `NSKeyedArchiver`.

## Return Value

The object graph previously encoded by `NSKeyedArchiver` written to the file `path`. Returns `nil` if there is no file at `path`.

## Discussion

This method raises an [`invalidArgumentException`](/documentation/Foundation/NSExceptionName/invalidArgumentException) if the file at `path` does not contain a valid archive.

---

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)