---
title: "makeSampleBuffer(for:addTo:)"
framework: avfoundation
role: symbol
role_heading: Instance Method
path: "avfoundation/avsamplebuffergenerator/makesamplebuffer(for:addto:)"
---

# makeSampleBuffer(for:addTo:)

Creates a sample buffer and attempts to defer I/O for its data.

## Declaration

```swift
func makeSampleBuffer(for request: AVSampleBufferRequest, addTo batch: AVSampleBufferGeneratorBatch) throws -> CMSampleBuffer
```

## Parameters

- `request`: A sample buffer creation request.
- `batch`: A batch object to contain the output sample buffer. You must create this object by calling doc://com.apple.avfoundation/documentation/AVFoundation/AVSampleBufferGenerator/makeBatch() on the same instance of doc://com.apple.avfoundation/documentation/AVFoundation/AVSampleBufferGenerator or an error occurs.

## Return Value

Return Value A sample buffer.

## Discussion

Discussion Call the makeDataReady(completionHandler:) on AVSampleBufferGeneratorBatch once to commence I/O and load sample data for all CMSampleBuffer objects in a batch. After loading commences, any subsequent calls to makeSampleBuffer(for:addTo:) throw an exception. The generator may defer I/O to fetch sample data depending on the source of the sample data and the generator’s timebase The request may fail based on generator configuration or file format.

## See Also

### Creating a sample buffer

- [makeSampleBuffer(for:)](avfoundation/avsamplebuffergenerator/makesamplebuffer(for:).md)
- [makeBatch()](avfoundation/avsamplebuffergenerator/makebatch().md)
- [createSampleBuffer(for:)](avfoundation/avsamplebuffergenerator/createsamplebuffer(for:).md)
