Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Compiler Error 'iostream' not found

I've tried to implement a project which I've found on github.

https://github.com/hossamghareeb/Facebook-POP-Tutorial

While I was implementing the .h and .m files I've got an error which was saying XCode could not find my 'iostream' file.

I'm working in SWIFT, using bridging-headers to use the framework. When I try to build the original project it works, but mine always fails.

enter image description here

How can I add my iostream file?

Thanks in advance!

like image 742
Hannes Van den Berghe Avatar asked Sep 28 '22 09:09

Hannes Van den Berghe


1 Answers

Swift bridging does not support Objective C++ files. This means that any headers that consume or expose C++ entites (like std::vector; std::iostream) cannot be added to the bridging header.

The POP bridging header contains:

#import "POP.h"

You should really only #import that file in your own bridging header, rather than trying to #import all the .h files.

If you need to consume some of the API that's defined in .mm files that isn't exposed with an Objective C or plain C header, then you'll have to make your own header file that exposes it (and probably a back-end that implements what you've exposed).

The reason why you can use .mm files in a library that's being used by Swift is because all swift uses is the interface to those files - i.e. the .h files, and as long as those files are in plain C or Objective C, then you can make use of the code that is implemented in the .mm file. The .mm files are compiled by Objective C++ compiler (clang++)

like image 71
Petesh Avatar answered Oct 05 '22 06:10

Petesh