<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTL4CommandBuffer/beginCommandBuffer(allocator:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTL4CommandBuffer(im)beginCommandBufferWithAllocator:"
  },
  "title" : "beginCommandBuffer(allocator:)"
}
-->

# beginCommandBuffer(allocator:)

Prepares a command buffer for encoding.

```
func beginCommandBuffer(allocator: any MTL4CommandAllocator)
```

## Parameters

`allocator`

[`MTL4CommandAllocator`](/documentation/Metal/MTL4CommandAllocator) to attach to.

## Discussion

Attaches the command buffer to the specified [`MTL4CommandAllocator`](/documentation/Metal/MTL4CommandAllocator) and declares that the
application is ready to encode commands into the command buffer.

Command allocators only service a single command buffer at a time. If you need to issue multiple
calls to this method simultaneously, for example, in a multi-threaded command encoding scenario,
create multiple instances of `MTLCommandAllocator` and use one for each call.

You can safely reuse command allocators after ending the command buffer using it by calling
[`endCommandBuffer()`](/documentation/Metal/MTL4CommandBuffer/endCommandBuffer()).

After calling this method, any prior calls to [`useResidencySet(_:)`](/documentation/Metal/MTL4CommandBuffer/useResidencySet(_:)) and [`useResidencySets:count:`](/documentation/Metal/MTL4CommandBuffer/useResidencySets:count:)
on this command buffer instance no longer apply. Make sure to call these methods again to signal
your residency requirements to Metal.

---

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)