<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFMutableData",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@T@CFMutableDataRef"
  },
  "title" : "CFMutableData"
}
-->

# CFMutableData

```
class CFMutableData
```

## Overview

CFMutableData manages dynamic binary data. The basic interface for managing binary data is provided by [`CFData`](/documentation/CoreFoundation/CFData). CFMutableData adds functions to modify the contents of a binary data object.

You create a mutable data object using either the [`CFDataCreateMutable(_:_:)`](/documentation/CoreFoundation/CFDataCreateMutable(_:_:)) or [`CFDataCreateMutableCopy(_:_:_:)`](/documentation/CoreFoundation/CFDataCreateMutableCopy(_:_:_:)) function.

Bytes are added to a data object with the [`CFDataAppendBytes(_:_:_:)`](/documentation/CoreFoundation/CFDataAppendBytes(_:_:_:)) function. Bytes are removed from a data object with the [`CFDataDeleteBytes(_:_:)`](/documentation/CoreFoundation/CFDataDeleteBytes(_:_:)) function.

> Important:
> Many of the CFMutableData functions take a ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFIndex`` `length` or `capacity` argument. You must not pass a negative number for such values—this may introduce a security risk.

CFMutableData is “toll-free bridged” with its Cocoa Foundation counterpart, <doc://com.apple.documentation/documentation/Foundation/NSMutableData>. What this means is that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. In other words, in a method where you see an `NSMutableData *` parameter, you can pass in a `CFMutableDataRef`, and in a function where you see a `CFMutableDataRef` parameter, you can pass in an `NSMutableData` instance. This also applies to concrete subclasses of `NSMutableData`. See [Toll-Free Bridged Types](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html#//apple_ref/doc/uid/TP40010677) for more information on toll-free bridging.

## Topics

### Creating a Mutable Data Object

[`CFDataCreateMutable(_:_:)`](/documentation/CoreFoundation/CFDataCreateMutable(_:_:))

Creates an empty CFMutableData object.

[`CFDataCreateMutableCopy(_:_:_:)`](/documentation/CoreFoundation/CFDataCreateMutableCopy(_:_:_:))

Creates a CFMutableData object by copying another CFData object.

### Accessing Data

[`CFDataGetMutableBytePtr(_:)`](/documentation/CoreFoundation/CFDataGetMutableBytePtr(_:))

Returns a pointer to a mutable byte buffer of a CFMutableData object.

### Modifying a Mutable Data Object

[`CFDataAppendBytes(_:_:_:)`](/documentation/CoreFoundation/CFDataAppendBytes(_:_:_:))

Appends the bytes from a byte buffer to the contents of a CFData object.

[`CFDataDeleteBytes(_:_:)`](/documentation/CoreFoundation/CFDataDeleteBytes(_:_:))

Deletes the bytes in a CFMutableData object within a specified range.

[`CFDataReplaceBytes(_:_:_:_:)`](/documentation/CoreFoundation/CFDataReplaceBytes(_:_:_:_:))

Replaces those bytes in a CFMutableData object that fall within a specified range with other bytes.

[`CFDataIncreaseLength(_:_:)`](/documentation/CoreFoundation/CFDataIncreaseLength(_:_:))

Increases the length of a CFMutableData object’s internal byte buffer, zero-filling the extension to the buffer.

[`CFDataSetLength(_:_:)`](/documentation/CoreFoundation/CFDataSetLength(_:_:))

Resets the length of a CFMutableData object’s internal byte buffer.

## See Also

  [Property List Programming Topics for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFPropertyLists/CFPropertyLists.html#//apple_ref/doc/uid/10000130i)

  [Binary Data Programming Guide for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBinaryData/CFBinaryData.html#//apple_ref/doc/uid/10000144i)



---

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)