Passing User Defined Swift Structure to C++ using In Param

I have a Usecase where I want to pass user-defined swift structure instance from Swift to C++ as argument to the C++ Function. In the documentation it's mentioned that swift exposes these structures to c++.

Swift Structure.


public struct MyStruct {
    
    public init (_ pValue : Int) {
        
        uValue = pValue
    }
    public var uValue : Int
}

I am able to Create Instance in C++ .

Code

void
CppClass::CreateSwiftStruct () 
{
    Interop::MyStruct my_struct = Interop::MyStruct::init (20);
}

But when I define a C++ Function which takes Interop::MyStruct as argument then that function doesn't get exposed to swift, so i am not able to call it.

Skeleton For CppClass

class CppClass {

static void PassStruct (Interop::MyStruct pStruct);

static void Test ();
}

Here PassStruct Method doesn't get exposed to C++ but Test does.

How can I pass Struct Instance in swift to C++ Function as In Param?

Answered by DTS Engineer in 803080022

This is an interesting question, one that I don’t have an immediate answer for. I recommend that you take it over to the Development > C++ Interoperability area of Swift Forums, where you’re more likely to find folks with relevant expertise.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

This is an interesting question, one that I don’t have an immediate answer for. I recommend that you take it over to the Development > C++ Interoperability area of Swift Forums, where you’re more likely to find folks with relevant expertise.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Passing User Defined Swift Structure to C++ using In Param
 
 
Q