<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSCoder/decodeTopLevelObjectAndReturnError:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCoder(im)decodeTopLevelObjectAndReturnError:"
  },
  "title" : "decodeTopLevelObjectAndReturnError:"
}
-->

# decodeTopLevelObjectAndReturnError:

Decodes a previously-encoded object, populating an error if decoding fails.

```
- (id) decodeTopLevelObjectAndReturnError:(NSError **) error;
```

## Parameters

`error`

An [`NSError`](/documentation/Foundation/NSError) reference. On return, if this value is not `nil`, it represents an error encountered while decoding.

## 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)