3
votes

I would like to create a Swift framework which links to Objective-C code.

The problem is that when I use bridging between my Swift code and the Objective-C code, compilation of the framework fails with "Using bridging headers with framework targets is unsupported".

The only solution I found (edit: similar to this one) was to import in my framework's umbrella header every Objective-C header that should be exposed to Swift, and then make these headers public.

As a result, I'm able to build a framework, but it contains all the Objective-C code. What I would like to achieve is to produce a framework which contains only the Swift part.

1
@l'L'l This is not a possible duplicate. I know about this question and the chosen answer but when I try it, I'm getting a framework which contains Swift and Objective-C. What I want is a framework that only contains Swift and that can be "externally linked" to the Objective-C code - Ariel Malka
I’m not sure what you mean by externally linked, can you please clarify? - l'L'l
Try module map, it doesn't require making the Objective-c header public. - kubrick G
@l'L'l By externally linked I mean: when compiling my framework, I'd like the Objective-C code (think of it as a 3rd party SDK) not to be included. Then later, when creating a new iOS project, I would include my framework (which contains only Swift) and also include the Objective-C code and everything should compile/link fine - Ariel Malka

1 Answers

1
votes

If I understand your question correctly, one approach might be to use a system module with a module map. Here is a nice tutorial on wrapping a C library, which should also work for an Objective-C lib: https://www.hackingwithswift.com/articles/87/how-to-wrap-a-c-library-in-swift. Then here is a discussion about using Xcode with SPM: https://forums.swift.org/t/xcode-project-with-spm-dependencies/18157.