<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 9.0.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSKeyedUnarchiver/decodeTopLevelDecodable(_:forKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:So17NSKeyedUnarchiverC10FoundationE23decodeTopLevelDecodable_6forKeyxSgxm_SStKSeRzlF"
  },
  "title" : "decodeTopLevelDecodable(_:forKey:)"
}
-->

# decodeTopLevelDecodable(_:forKey:)

Decodes a top-level decodable value associated with a given key.

```
@nonobjc func decodeTopLevelDecodable<T>(_ type: T.Type, forKey key: String) throws -> T? where T : Decodable
```

## Parameters

`type`

The type of the value to decode.

`key`

The key in the archive associated with the value to decode.

## Discussion

If the archive is not a valid property list, this method throws the <doc://com.apple.documentation/documentation/Swift/DecodingError/dataCorrupted(_:)> error. If a value within the archive fails to decode, this method throws the corresponding error.

---

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)