# Refine Swift API for C++?

**URL:** <https://forums.swift.org/t/refine-swift-api-for-c/83856>\
**Category:** C++ interoperability\
**Created:** [December 27, 2025, 9:15pm UTC](https://forums.swift.org/t/refine-swift-api-for-c/83856 "2025-12-27T21:15:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin\_Cornaby](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/colin_cornaby/32/8243_2.png) [@Colin\_Cornaby](https://forums.swift.org/u/Colin_Cornaby)\
**Post date:** [December 27, 2025, 9:15pm UTC](https://forums.swift.org/t/refine-swift-api-for-c/83856/1 "2025-12-27T21:15:51Z")

</div>

I’m working in a code base that uses both Metal and Metal-cpp. Metal-cpp is a header provided by Apple that provides C++ bindings to the Metal framework. Metal-cpp has its own pointer compatible types. They can be cast to/from the Obj-C Metal types because its types are just thin shims who just call objc\_msgsend on the underlying pointer.

This causes some problems for Swift/C++ interop though. I need to return the C++ Metal types from Swift, but I can’t use those types in Swift because they’re reference types. (Which would require messing with the header.) That means I need to use the Obj-C Metal types in my Swift code but return the C++ Metal types across the language boundary.

Is there a feature to refine functions for C++ like there is for Obj-C? I’d like to be able to change the return type. I know I can manually generate the header and then modify it. But I’m not sure that’s sustainable - I’m pretty sure that header changes every compilation.

---

<div class="post-metadata">

**Author:** ![technogen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/technogen/32/45489_2.png) [@technogen](https://forums.swift.org/u/technogen)\
**Post date:** [December 29, 2025, 3:56pm UTC](https://forums.swift.org/t/refine-swift-api-for-c/83856/2 "2025-12-29T15:56:12Z")

</div>

Not sure if you tried this or if it will work, but you may want to look into [API Notes](https://clang.llvm.org/docs/APINotes.html).

---

<div class="post-metadata">

**Author:** ![Colin\_Cornaby](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/colin_cornaby/32/8243_2.png) [@Colin\_Cornaby](https://forums.swift.org/u/Colin_Cornaby)\
**Post date:** [January 18, 2026, 6:16pm UTC](https://forums.swift.org/t/refine-swift-api-for-c/83856/3 "2026-01-18T18:16:41Z")

</div>

Sorry, I had a bit of the post holiday rush happen. Just getting back to this thread now.

I’ll look into API notes. Have those been used to refine a Swift generated C++ header within a target? I’ve seen them used to refine a stable header from a different module. But never a generated header in the same module.

---

<div class="post-metadata">

**Author:** ![technogen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/technogen/32/45489_2.png) [@technogen](https://forums.swift.org/u/technogen)\
**Post date:** [January 18, 2026, 6:19pm UTC](https://forums.swift.org/t/refine-swift-api-for-c/83856/4 "2026-01-18T18:19:16Z")

</div>

Honestly, I’m not sure. I haven’t experimented with generated headers before. Theoretically, if the generated headers are being built as part of a module and the API Notes are being applied after the fact, I don’t see how this would be different from hand-written ones.

Looking forward to hearing how your experiment went! 🙂
