<!--
{
  "availability" : [
    "iOS: 2.0.0 - 11.0.0",
    "iPadOS: 2.0.0 - 11.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.0.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSUnarchiver/unarchiveObject(with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSUnarchiver(cm)unarchiveObjectWithData:"
  },
  "title" : "unarchiveObject(with:)"
}
-->

# unarchiveObject(with:)

Decodes and returns the object archived in a given `NSData` object.

```
class func unarchiveObject(with data: Data) -> Any?
```

## Parameters

`data`

An `NSData` object that contains an archive created using `NSArchiver`.

## Return Value

The object, or object graph, that was archived in `data`. Returns `nil` if `data` cannot be unarchived.

## Discussion

This method invokes [`init(forReadingWith:)`](/documentation/Foundation/NSUnarchiver/init(forReadingWith:)) and [`decodeObject()`](/documentation/Foundation/NSCoder/decodeObject()) to create a temporary `NSUnarchiver` object that decodes the object. If the archived object is the root of a graph of objects, the entire graph is unarchived.

## See Also

[`-  encodeRootObject:`](/documentation/Foundation/NSArchiver/encodeRootObject(_:))

Archives a given object along with all the objects to which it is connected.



---

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)