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

# CFData

```
class CFData
```

## Overview

CFData and its derived mutable type, [`CFMutableData`](/documentation/CoreFoundation/CFMutableData), provide support for data objects, object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers) take on the behavior of Core Foundation objects. CFData creates static data objects, and CFMutableData creates dynamic data objects. Data objects are typically used for raw data storage.

You use the [`CFDataCreate(_:_:_:)`](/documentation/CoreFoundation/CFDataCreate(_:_:_:)) and [`CFDataCreateCopy(_:_:)`](/documentation/CoreFoundation/CFDataCreateCopy(_:_:)) functions to create static data objects. These functions make a new copy of the supplied data. To create a data object that uses the supplied buffer instead of making a separate copy, use the [`CFDataCreateWithBytesNoCopy(_:_:_:_:)`](/documentation/CoreFoundation/CFDataCreateWithBytesNoCopy(_:_:_:_:)) function. You use the [`CFDataGetBytes(_:_:_:)`](/documentation/CoreFoundation/CFDataGetBytes(_:_:_:)) function to retrieve the bytes and the [`CFDataGetLength(_:)`](/documentation/CoreFoundation/CFDataGetLength(_:)) function to get the length of the bytes.

CFData is “toll-free bridged” with its Cocoa Foundation counterpart, <doc://com.apple.documentation/documentation/Foundation/NSData>. 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 `NSData *` parameter, you can pass in a `CFDataRef`, and in a function where you see a `CFDataRef` parameter, you can pass in an `NSData` instance. This also applies to concrete subclasses of `NSData`. 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 CFData Object

[`func CFDataCreate(CFAllocator!, UnsafePointer<UInt8>!, CFIndex) -> CFData!`](/documentation/CoreFoundation/CFDataCreate(_:_:_:))

Creates an immutable CFData object using data copied from a specified byte buffer.

[`func CFDataCreateCopy(CFAllocator!, CFData!) -> CFData!`](/documentation/CoreFoundation/CFDataCreateCopy(_:_:))

Creates an immutable copy of a CFData object.

[`func CFDataCreateWithBytesNoCopy(CFAllocator!, UnsafePointer<UInt8>!, CFIndex, CFAllocator!) -> CFData!`](/documentation/CoreFoundation/CFDataCreateWithBytesNoCopy(_:_:_:_:))

Creates an immutable CFData object from an external (client-owned) byte buffer.

### Examining a CFData Object

[`func CFDataGetBytePtr(CFData!) -> UnsafePointer<UInt8>!`](/documentation/CoreFoundation/CFDataGetBytePtr(_:))

Returns a read-only pointer to the bytes of a CFData object.

[`func CFDataGetBytes(CFData!, CFRange, UnsafeMutablePointer<UInt8>!)`](/documentation/CoreFoundation/CFDataGetBytes(_:_:_:))

Copies the byte contents of a CFData object to an external buffer.

[`func CFDataGetLength(CFData!) -> CFIndex`](/documentation/CoreFoundation/CFDataGetLength(_:))

Returns the number of bytes contained by a CFData object.

[`func CFDataFind(CFData!, CFData!, CFRange, CFDataSearchFlags) -> CFRange`](/documentation/CoreFoundation/CFDataFind(_:_:_:_:))

Finds and returns the range within a data object of the first occurrence of the given data, within a given range, subject to any given options.

### Getting the CFData Type ID

[`func CFDataGetTypeID() -> CFTypeID`](/documentation/CoreFoundation/CFDataGetTypeID())

Returns the type identifier for the CFData opaque type.

### Data Types

[`struct CFDataSearchFlags`](/documentation/CoreFoundation/CFDataSearchFlags)

A [`CFOptionFlags`](/documentation/CoreFoundation/CFOptionFlags) type for specifying options for searching.

## 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)

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`Hashable`](/documentation/Swift/Hashable)

### Inherited By

[`CFMutableData`](/documentation/CoreFoundation/CFMutableData)

---

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)