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

# init(length:)

Initializes and returns a mutable data object containing a given number of zeroed bytes.

```
init?(length: Int)
```

## Parameters

`length`

The number of bytes the object initially contains.

## Return Value

An initialized `NSMutableData` object containing `length` zeroed bytes. The returned object has the same memory alignment guarantees as `malloc(_:)`.

## See Also

[`+  dataWithCapacity:`](/documentation/Foundation/NSMutableData/dataWithCapacity:)

Creates and returns a mutable data object capable of holding the specified number of bytes.

[`+  dataWithLength:`](/documentation/Foundation/NSMutableData/dataWithLength:)

Creates and returns an mutable data object containing a given number of zeroed 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)