Excluding internal headers from framework umbrella header

喜夏-厌秋 提交于 2021-02-04 13:45:25

问题


While trying to begin using Swift in a framework (including turning on module support), I started getting messages like this:

[snip]/<module-includes>:1:1: Umbrella header for module 'PressKit' does not include header 'NPKBaseAppearance.h'

The headers in question (there are about ten of them) are not listed in PressKit.h, but with good reason—they include internal or rarely-used classes and categories that I don't want to expose to most users of my framework. (Some of them I'd like to expose in select places; others should never be exposed.)

Marking the headers as private doesn't seem to help. This is a warning in my framework's project, but an error in each target using the framework, so I can't just ignore the problem.

Obviously I can add these headers to my umbrella header, but I don't want to. Am I violating some rule of framework design when using modules? What's the recommended way to handle this sort of situation?


回答1:


Don't know if you already solved this issue yourself but did you try to exclude the headers you don't want to export in a custom .modulemap file?

Have a look at: Clang 3.7 documentation - Modules




回答2:


What's the recommended way to handle this sort of situation?

Not sure if it's the recommended way, but here's how I got rid of that warning:

  1. I've created a private module map that lists all internal headers and placed it in the root folder of my framework project, as module.private.modulemap:

    framework module PressKit_Private {
        header "NPKBaseAppearance.h"
        export *
    }
    
  2. I have configured Xcode to use that module map

  1. I configured Xcode to treat those internal headers as private headers. That will cause Xcode to place them in PressKit.framework/PrivateHeaders when creating the framework.

Now, when importing the PressKit module in Swift or Objective-C, the functions from the headers from the private module map are not available. One needs to import PressKit_Private to make them available.



来源:https://stackoverflow.com/questions/29091369/excluding-internal-headers-from-framework-umbrella-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!