0

The problem is that I don't what to write C code. I have some libraries - for example for building suffix automaton for a given text and it is much more comfortable to write this with C++. Then I want to write swift app with such class, but how to do it without writing C code and without some restrictions on using C++ code. For example in my test.cpp I have

#include "test.h"
#include <string>

std::string hello() {
 return "Hello";
}

In my bridge I have:

#include "test.h"

But there is problems with test.h. Without using C I can't just write

#include <string>
std::string hello();
m8dotpie
  • 3
  • 2
  • 3
    You *cannot* call C++ code from Swift, see for example https://stackoverflow.com/q/35229149/1187415 or https://stackoverflow.com/q/48971931/1187415. – Martin R Jan 02 '20 at 21:59
  • 1
    You have two choices: Objective-C++ with which you use the Objective-C part to bridge Swift to Objective-C to Objective-C++ to the C++ part, or a C thunking layer that bridges from Swift to C to C++. – Eljay Jan 02 '20 at 22:18
  • C++ is, for most practical purposes, a superset of C. So, if you are comfortable with C++, you should be comfortable with C. I agree with the 2 earlier comments. If you run into specific problems, don't hesitate to come up with simple reproducible examples that demonstrate them, and people here will probably help you out. – Anatoli P Jan 03 '20 at 00:54

0 Answers0