---
title: "unarchivedObject(ofClasses:from:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nskeyedunarchiver/unarchivedobject(ofclasses:from:)-3h32t"
---

# unarchivedObject(ofClasses:from:)

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

## Declaration

```swift
@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 doc://com.apple.foundation/documentation/Foundation/NSKeyedArchiver.

## Return Value

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

Discussion This method produces an error if data does not contain valid keyed data. important: Make sure you have adopted NSSecureCoding in the types you decode. If any call to a decode-prefixed method fails, the default decodingFailurePolicy sets the error rather than throwing an exception. In this case, the current and all subsequent decode calls return 0 or nil.

## See Also

### Unarchiving Data

- [unarchiveTopLevelObjectWithData(_:)](foundation/nskeyedunarchiver/unarchivetoplevelobjectwithdata(_:).md)
- [unarchivedObject(ofClass:from:)](foundation/nskeyedunarchiver/unarchivedobject(ofclass:from:).md)
- [unarchivedObject(ofClasses:from:)](foundation/nskeyedunarchiver/unarchivedobject(ofclasses:from:)-b9t5.md)
- [requiresSecureCoding](foundation/nskeyedunarchiver/requiressecurecoding.md)
- [unarchiveObject(with:)](foundation/nskeyedunarchiver/unarchiveobject(with:).md)
- [unarchiveObject(withFile:)](foundation/nskeyedunarchiver/unarchiveobject(withfile:).md)
