How to bridge C with a Metal game?

I created a Metal game in Xcode. I am planning to write most of it in C, and write the user interface in Metal/Swift. However, Unlike SwiftUI, for a Metal game if I create a C file it does not automatically ask me to add a bridging header. So I research a ton, and try to add one, but it does not recognize it. Here's a screenshot. What am I doing wrong, many research efforts got me to "Add the name of the bridging header to this setting." I do it and nothing happens. What am I doing wrong, why do the other research websites lie, and what is the real way to accomplish this task?


The error I get is from trying to call a C function from swift, because it does not recognise the bridging header.


How can I manually create a bridging header in a Metal game

Replies

Write an Objective C wrapper class for your C library functions.


You can make the functions into Objective C class methods, if there is no resonable mappiing to object instance methods.


I had a fair bit of Objective C++ code in my app and there is no wrapper support for C++.

I recommend not to use Swift if you intend to use C or C++. It is just troublesome, use Objective-C or Objective-C++ instead and you do not have to write (a lot of) wrappers. Just under very special circumstances you may need a wrapper.