What happened to `Data(rawCapacity:)` initializer?

Greetings!

Trying to understand how to work with output spans. I noticed this WWDC session showcases the use of:

 let pixelData = Data(rawCapacity: totalBytes) { outputSpan in

Which does not seem to exist in Foundation as of 6.2.

The same example in Swift Binary Parsing has:

// TODO: Use OutputRawSpan instead of Data
var pixelData = Data(capacity: header.pixelCount * channels)

Which leads me to believe the feature didn’t make the cut.

Does anyone know of a work-around way of obtaining a OutputRawSpan that does not involve unsafe code?

Is there another safe and efficient way to output serialized binary representations of Swift structs?

Thanks!

1 Like

Hi Craig, that initializer didn’t make the release of Swift 6.2. It is still intended to appear in a future release of Swift.

1 Like