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

# decodeObject()

Decodes and returns an object that was previously encoded with any of the `encode…Object` methods.

```
func decodeObject() -> Any?
```

## Discussion

`NSCoder`’s implementation invokes [`decodeValue(ofObjCType:at:)`](/documentation/Foundation/NSCoder/decodeValue(ofObjCType:at:)) to decode the object data.

Subclasses may need to override this method if they override any of the corresponding `encode…Object` methods. For example, if an object was encoded conditionally using the [`encodeConditionalObject(_:)`](/documentation/Foundation/NSCoder/encodeConditionalObject(_:)) method, this method needs to check whether the object had actually been encoded.

## See Also

[`encodeByrefObject(_:)`](/documentation/Foundation/NSCoder/encodeByrefObject(_:))

An encoding method for subclasses to override such that it creates a proxy, rather than a copy, when decoded.

[`encodeBycopyObject(_:)`](/documentation/Foundation/NSCoder/encodeBycopyObject(_:))

An encoding method for subclasses to override such that it creates a copy, rather than a proxy, when decoded.

[`encode(_:)`](/documentation/Foundation/NSCoder/encode(_:)-9648d)

Encodes an object.



---

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)