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

# decodeObjectOfClass:forKey:

Decodes an object for the key, restricted to the specified class.

```
- (id) decodeObjectOfClass:(Class) aClass forKey:(NSString *) key;
```

## Parameters

`aClass`

The expect class type.

`key`

The coder key.

## Return Value

The decoded object.

## Discussion

If the coder responds <doc://com.apple.documentation/documentation/Swift/true> to [`requiresSecureCoding`](/documentation/Foundation/NSCoder/requiresSecureCoding), then an exception will be thrown if the class to be decoded does not implement [`NSSecureCoding`](/documentation/Foundation/NSSecureCoding) or is not <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol/isKind(of:)> of `aClass`.

If the coder responds <doc://com.apple.documentation/documentation/Swift/false> to [`requiresSecureCoding`](/documentation/Foundation/NSCoder/requiresSecureCoding), then the class argument is ignored and no check of the class of the decoded object is performed, exactly as if [`decodeObject(forKey:)`](/documentation/Foundation/NSCoder/decodeObject(forKey:)) had been called.

---

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)