Search code examples
objective-cswiftxcodecocoapodsadaptive-cards

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


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

Solution

  • 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