<!--
{
  "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/decodeBytes(withReturnedLength:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCoder(im)decodeBytesWithReturnedLength:"
  },
  "title" : "decodeBytes(withReturnedLength:)"
}
-->

# decodeBytes(withReturnedLength:)

Decodes a buffer of data whose types are unspecified.

```
func decodeBytes(withReturnedLength lengthp: UnsafeMutablePointer<Int>) -> UnsafeMutableRawPointer?
```

## Discussion

`NSCoder`‘s implementation invokes [`decodeValue(ofObjCType:at:)`](/documentation/Foundation/NSCoder/decodeValue(ofObjCType:at:)) to decode the data as a series of bytes, which this method then places into a buffer and returns. The buffer’s length is returned by reference in `numBytes`. If you need the bytes beyond the scope of the current `@autoreleasepool` block, you must copy them.

This method matches an [`encodeBytes(_:length:)`](/documentation/Foundation/NSCoder/encodeBytes(_:length:)) message used during encoding.

## See Also

[`encodeArray(ofObjCType:count:at:)`](/documentation/Foundation/NSCoder/encodeArray(ofObjCType:count:at:))

Encodes an array of the given Objective-C type, provided the number of items and a pointer.



---

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)