<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSUnarchiver"
  },
  "title" : "NSUnarchiver"
}
-->

# NSUnarchiver

A decoder that restores data from an archive.

```
class NSUnarchiver
```

## Overview

[`NSUnarchiver`](/documentation/Foundation/NSUnarchiver), a concrete subclass of [`NSCoder`](/documentation/Foundation/NSCoder), defines methods for decoding a set of Objective-C objects from an archive. Such archives are produced by objects of the [`NSArchiver`](/documentation/Foundation/NSArchiver) class.

In macOS 10.2 and later, [`NSArchiver`](/documentation/Foundation/NSArchiver) and [`NSUnarchiver`](/documentation/Foundation/NSUnarchiver) have been replaced by [`NSKeyedArchiver`](/documentation/Foundation/NSKeyedArchiver) and [`NSKeyedUnarchiver`](/documentation/Foundation/NSKeyedUnarchiver) respectively—see [Archives and Serializations Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Archiving/Archiving.html#//apple_ref/doc/uid/10000047i).

## Topics

### Initializing an NSUnarchiver

[`-  initForReadingWithData:`](/documentation/Foundation/NSUnarchiver/init(forReadingWith:))

Returns an `NSUnarchiver` object initialized to read an archive from a given data object.

### Decoding objects

[`+  unarchiveObjectWithData:`](/documentation/Foundation/NSUnarchiver/unarchiveObject(with:))

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

[`+  unarchiveObjectWithFile:`](/documentation/Foundation/NSUnarchiver/unarchiveObject(withFile:))

Decodes and returns the object archived in the file `path`.

### Managing an NSUnarchiver

[`atEnd`](/documentation/Foundation/NSUnarchiver/isAtEnd)

A Boolean value that indicates whether the receiver has reached the end of the encoded data while decoding.

[`-  objectZone`](/documentation/Foundation/NSUnarchiver/objectZone-c.method)

Returns the memory zone used to allocate decoded objects.

[`-  setObjectZone:`](/documentation/Foundation/NSUnarchiver/setObjectZone:)

Sets the memory zone used to allocate decoded objects.

[`systemVersion`](/documentation/Foundation/NSUnarchiver/systemVersion-swift.property)

The system version number in effect when the archive was created.

### Substituting classes or objects

[`+  classNameDecodedForArchiveClassName:`](/documentation/Foundation/NSUnarchiver/classNameDecoded(forArchiveClassName:)-swift.type.method)

Returns the name of the class used when instantiating objects whose ostensible class, according to the archived data, is a given name.

[`+  decodeClassName:asClassName:`](/documentation/Foundation/NSUnarchiver/decodeClassName(_:asClassName:)-swift.type.method)

Instructs instances of `NSUnarchiver` to use the class with a given name when instantiating objects whose ostensible class, according to the archived data, is another given name.

[`-  classNameDecodedForArchiveClassName:`](/documentation/Foundation/NSUnarchiver/classNameDecoded(forArchiveClassName:)-swift.method)

Returns the name of the class that will be used when instantiating objects whose ostensible class, according to the archived data, is a given name.

[`-  decodeClassName:asClassName:`](/documentation/Foundation/NSUnarchiver/decodeClassName(_:asClassName:)-swift.method)

Instructs the receiver to use the class with a given name when instantiating objects whose ostensible class, according to the archived data, is another given name.

[`-  replaceObject:withObject:`](/documentation/Foundation/NSUnarchiver/replace(_:with:))

Causes the receiver to substitute one given object for another whenever the latter is extracted from the archive.

## Relationships

### Conforms To

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Sendable`](/documentation/Swift/Sendable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

### Inherits From

[`NSCoder`](/documentation/Foundation/NSCoder)

---

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)