---
title: "decodeBytes(forKey:returnedLength:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nskeyedunarchiver/decodebytes(forkey:returnedlength:)"
---

# decodeBytes(forKey:returnedLength:)

Decodes a stream of bytes associated with a given key.

## Declaration

```swift
func decodeBytes(forKey key: String, returnedLength lengthp: UnsafeMutablePointer<Int>?) -> UnsafePointer<UInt8>?
```

## Parameters

- `key`: A key in the archive within the current decoding scope. key must not be nil.
- `lengthp`: Upon return, contains the number of bytes returned.

## Return Value

Return Value The stream of bytes associated with the key key. Returns NULL if key does not exist.

## Discussion

Discussion The returned value is a pointer to a temporary buffer owned by the receiver. The buffer goes away with the unarchiver, not the containing autorelease pool block. You must copy the bytes into your own buffer if you need the data to persist beyond the life of the receiver.

## See Also

### Related Documentation

- [encodeBytes(_:length:forKey:)](foundation/nskeyedarchiver/encodebytes(_:length:forkey:).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)
- [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)
- [decodeObject(forKey:)](foundation/nskeyedunarchiver/decodeobject(forkey:).md)
- [finishDecoding()](foundation/nskeyedunarchiver/finishdecoding().md)
- [decodingFailurePolicy](foundation/nskeyedunarchiver/decodingfailurepolicy.md)
