That's not currently supported. There are only two approaches for talking to C++ code from Swift code:
Wrap your C++ code in ObjC using Objective-C++, as you already found.
Take advantage of the fact that C++ is mostly compatible with C, and Swift can call C, and write a C wrapper around your C++ classes, and use that from Swift. A common approach would be:
cppwrapper.h
struct MyCppClass; // In C++ class and struct are the same, so this looks like a C struct to C, and as long as you don't look inside it, you can use pointers to it in C code.
extern "C" { // Tell C++ to turn off overloading based on type so it's C-compatible.
struct MyCppClass* MyCppClass_new( int firstParam );
void MyCppClass_delete( struct MyCppClass* inThis );
void MyCppClass_setFirstParam( struct MyCppClass* inThis, int firstParam );
} // extern "C"
cppwrapper.cpp
#include "cppwrapper.h"
#include "MyCppClass.hpp"
extern "C" MyCppClass* MyCppClass_new( int firstParam )
{
return new MyCppClass( firstParam );
}
extern "C" void MyCppClass_delete( MyCppClass* inThis )
{
delete inThis;
}
extern "C" void MyCppClass_setFirstParam( struct MyCppClass* inThis, int firstParam )
{
inThis->SetFirstParam( firstParam );
}
You could then even define a MyCppClassSwiftWrapper
that has an instance variable of type COpaquePointer in which you store the C++ object. This class would call MyCppClass_new
in its constructor, MyCppClass_delete
in its destructor, and would contain a wrapper around MyCppClass_setFirstParam
that uses the COpaquePointer as the inThis
parameter into it.
I once wrote a (very primitive) utility that lets you mark up C++ headers and generate simple C and Swift wrappers for them automatically (https://github.com/uliwitness/cpptoswift/) but it won't work with templates and you'll probably have to add more type mappings to it. It also doesn't yet handle passing/returning C++ objects correctly yet.
There's also https://github.com/sandym/swiftpp/ which does all that better, but I think it still uses Objective-C under the hood for its wrapper, but at least you don't have to write it yourself.