<!--
{
  "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/NSMutableData/length",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableData(py)length"
  },
  "title" : "length"
}
-->

# length

The number of bytes contained in the mutable data object.

```
var length: Int { get set }
```

## Discussion

The mutable data object’s length parameter is read-writeable. You can set this parameter to expand or truncate the number of bytes contained by the data object. If the mutable data object is expanded, the additional bytes are filled with zeros.

> Important:
> Changing the length of a mutable data object invalidate any existing data pointers returned by the ``doc://com.apple.foundation/documentation/Foundation/NSData/bytes`` or ``doc://com.apple.foundation/documentation/Foundation/NSMutableData/mutableBytes`` properties.

## See Also

[`-  increaseLengthBy:`](/documentation/Foundation/NSMutableData/increaseLength(by:))

Increases the length of the receiver by a given number of bytes.



---

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)