Creating pod in swift which have dependency on another objective-c pod

Viewed 630

Overview of my condition

As I explained in image I want to create Pod lib in swift which have another Pod lib dependency written in Objective-c.
Now I know that to use objective-c code in swift we need bridge file and I created it too. but When I set it into Pod's build phase I got this error<unknown>:0: error: using bridging headers with framework targets is unsupported

I got hint in internet that I should put .h file into pod-umbrella.h file, But that also gave me error Include of non-modular header inside framework module 'DemoPod'

  1. Please help me if you had similar issue in past and resolved it.
  2. Some hint/suggestions are also welcome.

Here is my demopod project for you if you want to play around.
Demo Pod Project

EDIT As per Ashsis suggestion I added below code into DemoPod.modulemap

framework module AdaptiveCard {
  umbrella header "/Users/jageen.shukla/Documents/Project/ai answer/DemoPod/Example/Pods/AdaptiveCards/AdaptiveCards.framework/Headers/ACFramework.h"
  requires ios
  export *
}

But still I can not build project because it give me error in target project that can not find module "AdaptiveCard". enter image description here

I change code in DemoPod.modulemap

framework module DemoPod {
  umbrella header "DemoPod-umbrella.h"
  
  // Solution 2
  framework module AdaptiveCard {
      umbrella header "/Users/jageen.shukla/Downloads/DemoPod/Example/Pods/AdaptiveCards/AdaptiveCards.framework/Headers/ACFramework.h"
      export *
      module * { export * }
  }
  // ----
  
  export *
  module * { export * }
}

Now I am able to compile my project. but I am not sure what I am doing is good practice or not? Plus I am also not know why I have to mention `absolute path` of adaptive card's header file.
Latest code : [Demo_2][4] https://drive.google.com/file/d/1Xve0DUAy4bQ7sx4d3H8WLbJJwTqlJnCt/view?usp=sharing
2 Answers

Bridging header is only recommended at App Target and App Test target to access objective c and CPP files in swift. You should use modulemap to expose the Objc and CPP functionality to swift library when it comes to static library or framework. Please check the code implementation how to use modulemap here: https://github.com/ashislaha/Swift-ObjectiveC-Interoperability

As the error says, bridging headers aren't allowed in frameworks, only in applications.

The detailed documentation is here

The Swift code will be able to access everything from objc that is included in the public umbrella header for your framework where it says

// In this header, you should import all the public headers of your framework using statements like #import <YourFramework/PublicHeader.h>  

You'll need to remove the bridging header from where you added it in the Build Settings, in order to get your framework to compile.

what should you do now ?

do this:

  1. Remove your bridging header file.
  2. Remove references to the bridging header file in the build settings for the framework
  3. Add the necessary headers to your umbrella file ([Name].h)
  4. Make the included files public in the framework's "Headers" section of its "Build Phases".

  5. Clean and rebuild.

Note: The "umbrella header file" is a file (named [ProductName].h) that generally represents all public headers of a framework. It is usually just a list of #import statements to other headers contained in the framework. In Xcode, if you open UIKit.h, you will see a good example of an umbrella file.

Related