I just finished watching the Mixing C, C++ and Swift session from WWDC 2025, great stuff and exciting improvements!
One thing that stood out was the introduction of the new Span and MutableSpan types, which offer a type-safe way to access underlying contiguous memory of Foundation types like Array and InlineArray. This looks like a promising step for C++ interoperability, especially for performance-sensitive use cases.
While browsing the documentation afterward, I noticed that Span and MutableSpan are both marked as beta, which makes sense given how new they are.
However, I didn't see similar span-based APIs added for Data, which is often used interchangeably with Array<UInt8> and also exposes a contiguous memory buffer. Since Data is a common type when dealing with byte buffers across C, C++, and Swift boundaries, I was wondering:
Will Data also support the new Span/MutableSpan approach for accessing its underlying memory in a type-safe and idiomatic way from C++?
Or, if there's a different recommended pattern when working with Data in C++ interop scenarios going forward, I'd love to hear more about that.
Thank you so much for the clarification and for pointing me to the Swift Foundation PR, really appreciate it!
I had checked the Apple Developer Documentation earlier for both Array and Data, and I could see the span API available for Array, but not for Data, which had me a bit confused. This clears things up!
It's great to know that the plan is to move most interactions with Data toward these new properties. Looking forward to adopting them as they become more widely integrated
Is there a way for a C++ class to hold an instance of Data, retained and safely?
I have a C++ type that has a size() and a uint8_t* data() method and it needs to hold underlying Swift Data, but I haven't figured out a way to do that without copy. Especially because the unsafe bytes accessors are always just closures.