<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XPC",
  "identifier" : "/documentation/XPC/xpc_data_create(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "c:@F@xpc_data_create"
  },
  "title" : "xpc_data_create(_:_:)"
}
-->

# xpc_data_create(_:_:)

Creates an XPC object that represents a buffer of bytes.

```
func xpc_data_create(_ bytes: UnsafeRawPointer?, _ length: Int) -> xpc_object_t
```

## Parameters

`bytes`

The buffer of bytes which is to be boxed. You may create an empty data object by passing NULL for this parameter and 0 for the length. Passing NULL with any other length will result in undefined behavior.

`length`

The number of bytes which are to be boxed.

## Return Value

A new data object.

## Discussion

This method will copy the buffer given into internal storage. After calling this method, it is safe to dispose of the given buffer.

---

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)