---
title: "unarchiveObject(with:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsunarchiver/unarchiveobject(with:)"
---

# unarchiveObject(with:)

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

## Declaration

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

## Parameters

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

## Return Value

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

## Discussion

Discussion This method invokes init(forReadingWith:) and 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

### Related Documentation

- [encodeRootObject(_:)](foundation/nsarchiver/encoderootobject(_:).md)

### Decoding objects

- [unarchiveObject(withFile:)](foundation/nsunarchiver/unarchiveobject(withfile:).md)
