<!--
{
  "availability" : [
    "iOS: 9.0.0 - 12.0.0",
    "iPadOS: 9.0.0 - 12.0.0",
    "macCatalyst: 9.0.0 - 12.0.0",
    "macOS: 10.11.0 - 10.14.0",
    "swift: 4.0.0 -",
    "tvOS: 9.0.0 - 12.0.0",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 - 5.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSKeyedUnarchiver/unarchiveTopLevelObjectWithData(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:So17NSKeyedUnarchiverC10FoundationE31unarchiveTopLevelObjectWithDatayypSgAC0I0VKFZ"
  },
  "title" : "unarchiveTopLevelObjectWithData(_:)"
}
-->

# unarchiveTopLevelObjectWithData(_:)

Decodes a previously-archived object graph, and returns the root object.

```
@nonobjc class func unarchiveTopLevelObjectWithData(_ data: Data) throws -> Any?
```

## Parameters

`data`

An object graph previously encoded by [`NSKeyedArchiver`](/documentation/Foundation/NSKeyedArchiver).

## Return Value

The unarchived object, or `nil` if an error occurred.

## Discussion

This method throws an error if `data` does not contain valid keyed data.

---

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)