Swift-ObjectiveC-Interoperability icon indicating copy to clipboard operation
Swift-ObjectiveC-Interoperability copied to clipboard

How to mix Swift & Objective-C in a static library?

Open jsorge opened this issue 5 years ago • 2 comments

First, thank you so much for your blog post. It's been helping me a ton to figure this stuff out.

But I'm curious how I'd go about mixing Swift & Objective-C in a static library. I have a framework that I want to make into a static library that has a private module as well to share code internally between Swift & Objective-C code (so this would require a module.private.modulemap file, which also means I need to make my module map by hand).

I see that on a framework target, the built product has a Modules/module.modulemap file which has a sub-module to expose the Swift generated header to Objective-C like so:

framework module MyFramework {
  umbrella header "MyFramework.h"

  export *
  module * { export * }
}

module MyFramework.Swift {
    header "MyFramework-Swift.h"
    requires objc
}

I'm not sure if there's a way for me to manually make this file to also then have my private module map expose the internal Objective-C to my internal Swift.

If you've got any ideas on how I can proceed here I'd much appreciate it. Thanks again!

jsorge avatar Oct 28 '20 22:10 jsorge

Hey Sorry, I was quite inactive on GitHub. is it resolved?

ashislaha avatar Mar 08 '21 11:03 ashislaha

No worries! I was actually able to get this working by using a static framework instead of a static library. It seems that frameworks in this situation works quite a bit better (at least that's what I'm finding).

jsorge avatar Mar 18 '21 14:03 jsorge