<!--
{
  "availability" : [
    "iOS: 2.0.0 - 12.0.0",
    "iPadOS: 2.0.0 - 12.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.2.0 - 10.14.0",
    "tvOS: 9.0.0 - 12.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 5.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSKeyedUnarchiver/init(forReadingWith:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSKeyedUnarchiver(im)initForReadingWithData:"
  },
  "title" : "init(forReadingWith:)"
}
-->

# init(forReadingWith:)

Initializes an archiver to decode data from the specified location.

```
init(forReadingWith data: Data)
```

## Parameters

`data`

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

## Return Value

An [`NSKeyedUnarchiver`](/documentation/Foundation/NSKeyedUnarchiver) object initialized for for decoding `data`.

## Discussion

When you finish decoding data, you should invoke [`finishDecoding()`](/documentation/Foundation/NSKeyedUnarchiver/finishDecoding()).

This method throws an exception if `data` is not a valid archive.

## See Also

  [Archives and Serializations Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Archiving/Archiving.html#//apple_ref/doc/uid/10000047i)



---

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)