# Swift functions with c++ enums arguments not available in c++

**URL:** <https://forums.swift.org/t/swift-functions-with-c-enums-arguments-not-available-in-c/70568>\
**Category:** C++ interoperability\
**Created:** [March 11, 2024, 8:41am UTC](https://forums.swift.org/t/swift-functions-with-c-enums-arguments-not-available-in-c/70568 "2024-03-11T08:41:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![geertb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/geertb/32/34401_2.png) [@geertb](https://forums.swift.org/u/geertb)\
**Post date:** [March 11, 2024, 8:41am UTC](https://forums.swift.org/t/swift-functions-with-c-enums-arguments-not-available-in-c/70568/1 "2024-03-11T08:41:28Z")

</div>

I'm trying to develop a mix-language (c++ and Swift) framework where calls are mainly from c++ -\> Swift. However, I'm having problems with get Swift functions available in c++ when they take a c++ enum value as parameter.

Assume the following c++ header:

```cpp
#pragma once

enum class MyCppEnumClass { A, B, C };
enum MyCppEnum { D, E, F };

```

and following Swift source file:

```swift
public func swiftFunctionWithCppEnumClass(_ value: MyCppEnumClass) {
  print("Swift function with C++ enum: \(value)")
}

public func swiftFunctionWithCppEnum(_ value: MyCppEnum) {
  print("Swift function with C++ enum: \(value)")
}

```

The (Xcode) project compiles correctly this way, so the bridging of the enum types does work, making both the enum and enum class available in Swift. However, when inspecting the generated Swift header, I'm seeing this:

```cpp
namespace CxxInteropExperiments SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("CxxInteropExperiments") {

// Unavailable in C++: Swift global function 'swiftFunctionWithCppEnum(_:)'.

// Unavailable in C++: Swift global function 'swiftFunctionWithCppEnumClass(_:)'.

} // namespace CxxInteropExperiments

```

If I understand the documentation correctly, this should be supported:

 ![image](https://global.discourse-cdn.com/swift/original/3X/3/6/36d765b330b94e23b75ce0f3c3ef1d48e5b0ee00.png)  
The parameter is a C++ struct, class or enumeration (2nd bullet in the list), so I'd expect this to work.

Am I missing something obvious here that makes the Swift functions not available in C++.

The only workaround I can figure out is to 'mirror' the enum class on swift and write a converter function in C++, like so:

```swift
public enum MySwiftEnum {
  case A
  case B
  case C
}

public func swiftFunctionWithSwiftEnum(_ value: MySwiftEnum) {
  print("Swift function with Swift enum: \(value)")
}

```

```cpp
#include <CxxInteropExperiments/CxxInteropExperiments-Swift.h>

CxxInteropExperiments::MySwiftEnum convert(MyCppEnumClass e) {
  switch(e) {
    case MyCppEnumClass::A: return CxxInteropExperiments::MySwiftEnum::A();
    case MyCppEnumClass::B: return CxxInteropExperiments::MySwiftEnum::B();
    case MyCppEnumClass::C: return CxxInteropExperiments::MySwiftEnum::C();
  }
}

void callSwiftFunctionWithEnum(MyCppEnumClass e) {
  CxxInteropExperiments::swiftFunctionWithSwiftEnum(convert(e));
}

```

Any info or advice is appreciated.

I'm using Xcode 15.3.  
A sample Xcode project demonstration the issue (zip file hosted on my iCloud):

> **[iCloud Drive - Apple iCloud](https://www.icloud.com/iclouddrive/0c8AhY4hLWWcptgaKHKqw9Jsg#CxxInteropExperiments)**
>
> Store, organize and collaborate on files and folders with iCloud Drive. Easily upload, delete or recover files. Changes will sync across your devices with iCloud.
