0

I have to use a third-party library into one of my OSX applications. The app itself will be in Swift, but the compiled library exposes what seems to be Objective-C++ functions through a header.

It should normally only require a bridging header, but I have strange errors concerning some functions in the library-provided .h when included in my bridging one:

+ (const char *)funcName:(const aStructType &)something;

This line (which looks like most lines in the .h) for example generates two errors:

Must use 'struct' tag to refer to type 'aStructType'

and

Expected ')'

The first error refers to the struct type and the second one to the ampersand.

I first tried to make an Objective-C Bridge as suggested by previous answers on SO (with the .h included in the .mm), but the many conflicting types quickly became a mess and caused too many compile errors. Furthermore delegate patterns became impossible to work with and translate to Swift while avoiding any type from the framework.

My second solution was to simply correct the header by hand for testing purposes, changing the example line before to this:

+ (const char *)funcName:(const struct aStructType)something;

It worked and data was coming through, but structures where apparently broken by what seems to be a number type issue. Nevermind the fact that it just seems absolutely insane to simply change a header.

The library seems to works just fine with Objective-C++ code only app, so i'm not sure where the issue is coming from.

I tried to stay pretty generic, but let me know if you need more detail on the framework itself!

Thanks!

  • The signature in your question doesn't have any C++ implications. The data types are C, which should be fine if you declare them as expected (which you seem to have done). For this specific example, maybe focus on the "number type issue". (If you really do have C++ objects exposed somewhere, that's going to be a bigger problem.) – Phillip Mills Feb 21 '16 at 00:07
  • @PhillipMills Thanks for your help! To be honest, I don't know. I'm assuming C++ because I need .mm files for the code to compile. I think understanding the `&` and how to use this without modifying the header file (since it was provided, not my creation) would probably be the smartest way to approach it. The number type issue is a result of changing the header, and I'm now trying to reproduce it without Swift. – Ashamed question Feb 21 '16 at 00:23
  • Assuming you really do have C++ exposed, based on "I need .mm files for the code to compile", I think you're back to needing an Objective-C layer to keep the C++ code/objects from being seen by Swift. – Phillip Mills Feb 21 '16 at 01:21
  • @PhillipMills Okay! I'll just try to make a wrapper again. Thank you! – Ashamed question Feb 21 '16 at 01:29

0 Answers0