How to import private framework headers in a Swift framework?

后端 未结 4 1043
挽巷
挽巷 2020-12-07 23:15

I have an Objective-C framework (framework A) that exposes some public and some private headers. The public headers are also declared in the framework\'s umbrella header. I

4条回答
  •  广开言路
    2020-12-07 23:55

    My situation may be particular to my setup, but I'll offer it here, in case it helps someone else. I also have an Objective-C framework (framework A) with private headers that I need to use in a Swift framework (framework B) that links it. Some additional details:

    1. Each framework is in a separate project in the workspace

    2. The project uses CocoaPods

    3. The podspec defines the following dependence relationship between the two frameworks:

      s.subspec 'FrameworkA' do |cs|
          cs.vendored_frameworks = "lib/FrameworkA.framework"
      end
      
      s.subspec 'FrameworkB' do |ts|
          ts.dependency 'FrameworkA'
          ts.vendored_frameworks = "lib/FrameworkB.framework"
      end
      

    The solution offered by @rintaro works great for me when running in Xcode, but once the Pod is deployed, FrameworkB is unable to find the private headers using the paths in the private modulemap that lives in FrameworkA. What worked for me was to use a relative path to the PrivateHeaders dir in the private modulemap:

    module FrameworkA_Private {
        header "../FrameworkA.framework/PrivateHeaders/Private.h"
        export *
    }
    

    This works in Xcode and in the final product installed using CocoaPods. It's a little bit hacky, since it references a folder in the final build product, and I wouldn't be surprised if there's some other way to tell CocoaPods how to preserve these paths, but whatever it is, I haven't found it. This solves the problem for now.

提交回复
热议问题