<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 11.0.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 4.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSKeyedUnarchiver/unarchivedObject(ofClasses:from:)-3h32t",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:So17NSKeyedUnarchiverC10FoundationE16unarchivedObject9ofClasses4fromypSgSayyXlXpG_AC4DataVtKFZ"
  },
  "title" : "unarchivedObject(ofClasses:from:)"
}
-->

# unarchivedObject(ofClasses:from:)

Decodes a previously-archived object graph, returning the root object as one of the specified classes.

```
@nonobjc static func unarchivedObject(ofClasses classes: [AnyClass], from data: Data) throws -> Any?
```

## Parameters

`classes`

A set of classes, at least one of which the root object should conform to.

`data`

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

## Return Value

The decoded root of the object graph, as an instance of one of the specified classes, or `nil` if an error occurred.

## Discussion

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

> Important:
> Make sure you have adopted ``doc://com.apple.foundation/documentation/Foundation/NSSecureCoding`` in the types you decode. If any call to a `decode`-prefixed method fails, the default ``doc://com.apple.foundation/documentation/Foundation/NSKeyedUnarchiver/decodingFailurePolicy`` sets the error rather than throwing an exception. In this case, the current and all subsequent decode calls return `0` or `nil`.

---

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)