Swift and Objective C++ Mixed Language Framework and Modules

Hi,

I am writing a Swift framework that primarily serves as a wrapper for a linear algebra library written in C. The framework therefore is a mixture of Swift and Objective C (the Objective C part is there to serve as a bridge to allow the Swift code to talk to the C

I have reviewed the documents on Clang modules and looked at various code examples on the Web. However, I am still not finding a clear path and have had difficulties getting the code to compile (I am also unclear what the official recommendations are for achieving the goal I desire). Here are a few questions:

1) Is it good practice to create mixed languages frameworks that are a combination of Swift and Objective C++? If so, are there examples available that show best practices? If not, what is a workaround?

2) I don’t want to expose the Objective C++ part of the code to the consumer of my framework. I am not clear how to do this. I have read about private modules. However, I am unclear about how to properly use private modules in this context and again lack clear examples.

3) What is the recommended practice when creating module.map files in XCode when XCode itself generates a default module.map file when building a framework? Again, there are some examples on the Web, but I am unclear whether they are correct an none of them explicitly suits my goals.

4) Where is the official documentation on how to properly use module.map files in XCode especially with respect to building frameworks that rely on both Swift and Objective C++?

5) Although I know that if this weren’t a framework, I could create a bridging header to allow Swift to talk to Objective C++. However, in the case of a module there is an umbrella header. My understanding of the umbrella header is that it pertains to code that will consume the framework, not for other code in the framework itself. Can you somehow combine an umbrella header and a bridging header in a framework?

Thanks in advance
Can you clarify precisely what you are talking about? You started talking about interfacing Swift with C, which is more or less trivial. But then you switch to interfacing Swift with C++, which is more or less impossible.

The first thing I would suggest is to review exactly what your library is doing. Apple already provides linear algebra frameworks in the operating system.

I'm not sure about your questions. I you are writing a C framework, you can do that. You cannot expose a Swift version of that. You would have to expose a plain C version and then import that into Swift. The only way to integrate Swift with C is via Objective-C. You can wrap all of the C in Objective-C and then import the Objective-C. But you make to make sure that no C code is visible to Swift.
Ugh! Sorry about that. I now see the reason why you are switching from C to C++. It's the #%^& markdown.
Regarding item 2. Create a modulemap file named module.modulemap and add the Objective C headers you want to keep private but expose to Swift:

Code Block
module frameworkPrivate {
  header "relative/path/file1.h"
  header "relative/path/file2.h"
  export *
}


In the Build Settings of your framework target add the following to Import Paths:

Code Block
$(SRCROOT)/path/to/frameworkPrivate


In your Swift files add

Code Block
import frameworkPrivate



@jon2718 Did you find the answer to your question? I am also in the same boat as you. I am writing a new framework and my project has Objective-C++ files. I cannot import my swift framework into my project.

Swift and Objective C++ Mixed Language Framework and Modules
 
 
Q