3

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.

7
  • Possible duplicate of Objective C Bridging Header for frameworks Commented Jan 28, 2019 at 18:43
  • @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 Commented Jan 28, 2019 at 20:26
  • I’m not sure what you mean by externally linked, can you please clarify? Commented Jan 29, 2019 at 0:52
  • Try module map, it doesn't require making the Objective-c header public. Commented Jan 29, 2019 at 4:47
  • @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 Commented Jan 29, 2019 at 13:37

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried module maps, as explained in the link provided by Kubrick G. The nice part is indeed that Objective-C headers are not included in the produced framework. But I'm still stuck, because the produced framework still contains the Objective-C code. As a result, when I include the framework in a new project, which also contains the Objective-C code, I get errors of type "class foo is implemented in both..."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.