-
Swift (
ContentView.swift)
Calls the C-style function exposed via the bridging header:Text("Hello from: \(String(cString: test()))")
-
Bridging Header (
swift_cpp-Bridging-Header.h) Makes the C-style function available to Swift:#include "MyCpp.h"
-
C++ Header (
MyCpp.h) Declares the function usingextern "C"to prevent C++ name mangling:#ifndef MyCpp_h #define MyCpp_h #ifdef __cplusplus extern "C" { #endif const char* test(); #ifdef __cplusplus } #endif #endif /* MyCpp_h */
-
C++ Implementation (
MyCpp.cpp) Defines the function using C++ syntax:#include "MyCpp.h" const char* test() { return "C++"; }
da-nish/swift_cpp_-interoperability
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|