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

# decodeTopLevelObject(forKey:)

Decodes the previously-encoded object associated by a key.

```
@nonobjc func decodeTopLevelObject(forKey key: String) throws -> Any?
```

## Parameters

`key`

The key that identifies the object to decode.

## Return Value

The decoded object, or `nil` if decoding fails.

---

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)