Skip to content

da-nish/swift_cpp_-interoperability

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

🧩 Components

  1. Swift (ContentView.swift)
    Calls the C-style function exposed via the bridging header:

    Text("Hello from: \(String(cString: test()))")
  2. Bridging Header (swift_cpp-Bridging-Header.h) Makes the C-style function available to Swift:

    #include "MyCpp.h"
  3. C++ Header (MyCpp.h) Declares the function using extern "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 */
  4. C++ Implementation (MyCpp.cpp) Defines the function using C++ syntax:

    #include "MyCpp.h"
    
    const char* test() {
        return "C++";
    }

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors