---
title: "decodeObject(forKey:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nskeyedunarchiver/decodeobject(forkey:)"
---

# decodeObject(forKey:)

Decodes and returns an object associated with a given key.

## Declaration

```swift
func decodeObject(forKey key: String) -> Any?
```

## Parameters

- `key`: A key in the archive within the current decoding scope. key must not be nil.

## Return Value

Return Value The object associated with the key key. Returns nil if key does not exist, or if the value for key is nil.

## See Also

### Related Documentation

- [encode(_:forKey:)](foundation/nskeyedarchiver/encode(_:forkey:)-9f4n9.md)

### Decoding Data

- [containsValue(forKey:)](foundation/nskeyedunarchiver/containsvalue(forkey:).md)
- [decodeDecodable(_:forKey:)](foundation/nskeyedunarchiver/decodedecodable(_:forkey:).md)
- [decodeTopLevelDecodable(_:forKey:)](foundation/nskeyedunarchiver/decodetopleveldecodable(_:forkey:).md)
- [decodeBool(forKey:)](foundation/nskeyedunarchiver/decodebool(forkey:).md)
- [decodeBytes(forKey:returnedLength:)](foundation/nskeyedunarchiver/decodebytes(forkey:returnedlength:).md)
- [decodeDouble(forKey:)](foundation/nskeyedunarchiver/decodedouble(forkey:).md)
- [decodeFloat(forKey:)](foundation/nskeyedunarchiver/decodefloat(forkey:).md)
- [decodeInt32(forKey:)](foundation/nskeyedunarchiver/decodeint32(forkey:).md)
- [decodeInt64(forKey:)](foundation/nskeyedunarchiver/decodeint64(forkey:).md)
- [finishDecoding()](foundation/nskeyedunarchiver/finishdecoding().md)
- [decodingFailurePolicy](foundation/nskeyedunarchiver/decodingfailurepolicy.md)
