<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.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/init(forReadingFrom:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSKeyedUnarchiver(im)initForReadingFromData:error:"
  },
  "title" : "init(forReadingFrom:)"
}
-->

# init(forReadingFrom:)

Initializes an archiver to decode data from the specified location.

```
init(forReadingFrom data: Data) throws
```

## Parameters

`data`

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

## Discussion

This initializer enables [`requiresSecureCoding`](/documentation/Foundation/NSKeyedUnarchiver/requiresSecureCoding) by default, and sets the [`decodingFailurePolicy`](/documentation/Foundation/NSKeyedUnarchiver/decodingFailurePolicy) to [`NSCoder.DecodingFailurePolicy.setErrorAndReturn`](/documentation/Foundation/NSCoder/DecodingFailurePolicy-swift.enum/setErrorAndReturn).

Call [`finishDecoding()`](/documentation/Foundation/NSKeyedUnarchiver/finishDecoding()) when you finish decoding data

This method throws an error if `data` isn’t a valid keyed archive.

> Important:
> If you are adapting existing code to use this initializer, 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 ``doc://com.apple.foundation/documentation/Foundation/NSCoder/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)