---
title: "init(forReadingFrom:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nskeyedunarchiver/init(forreadingfrom:)"
---

# init(forReadingFrom:)

Initializes an archiver to decode data from the specified location.

## Declaration

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

## Parameters

- `data`: An archive previously encoded by doc://com.apple.foundation/documentation/Foundation/NSKeyedArchiver.

## Discussion

Discussion This initializer enables requiresSecureCoding by default, and sets the decodingFailurePolicy to NSCoder.DecodingFailurePolicy.setErrorAndReturn. Call 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 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

### Creating a Keyed Unarchiver

- [init()](foundation/nskeyedunarchiver/init().md)
- [init(forReadingWith:)](foundation/nskeyedunarchiver/init(forreadingwith:).md)
