I am trying to call some C++ code in a Swift application. I did not write the C++ nor do I have control over it.
I have created a C++ wrapper to handle the calls from Swift. I also added some test functions within the C++ files to verify that I am calling the C++ from Swift. Those functions simply return an int.
In the C++ header code there is a function defined as follows:
class GlobeProcessor {
public:
void readFile(ifstream &inputFile);
// ...
};
In my wrapper I have defined the function as follows:
extern "C" void processGlobe(ifstream &file) {
GlobeProcessor().readFile(file);
}
The confusing part is how to reference this in my bridging header. Currently the bridging header contains the following:
// test function
int getNumber(int num);
void processGlobeFile(ifstream &file);
The test function succeeds, so I am able to access the C++ from Swift. However, adding a declaration for processGlobeFile
to the bridging header produces the following compile error:
Unknown type name 'ifstream'
I have tried unsuccessfully to add the appropriate imports to the bridging header. I am not a seasoned C++ guy, so i don't really know if I'm approaching this in the correct manner. Can somebody help me to understand how to pass a file as a parameter to a C++ method from Swift?
Thanks!