如何在Swift框架中导入私有框架头文件? [英] How to import private framework headers in a Swift framework?
问题描述
我有一个Objective-C框架(框架A),暴露一些公共和一些私有头。公共头部也在框架的伞头中声明。我有一个与Objective-C框架链接的第二个Swift框架(框架B)。
现在,如果我想导入A的公共头部做一个 import A
。
但是如何导入私有头?
我知道桥接头不是一个选项,因为不支持框架。我需要以某种方式为私有头创建一个单独的伞头吗?
你需要修改框架 A
,以便导出私有模块。
-
创建 A 项目中的http://clang.llvm.org/docs/Modules.html#private-module-map-files\">私有模块映射文件。这将是这样:
A / private.modulemap :
显式模块A.Private {
//这是你的私有头文件的列表。
headerPrivate1.h
headerPrivate2.h
export *
}
-
在框架
A
目标的Build Settings中,搜索Private Module Map File并使其:$(SRCROOT)/A/private.modulemap
-
不要在编译源中包含
private.modulemap
文件。这会导致不必要的警告。 -
清洁和构建框架
A
>
-
在框架B Swift文件中。您可以像这样导入私有模块:
import A
import A.Private
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 have a second Swift framework (framework B) that links with the Objective-C framework.
Now, if I want to import the public headers of A in B I simply need to do an import A
.
But how do I go about importing the private headers?
I know a bridging header is not an option since that's not supported for frameworks. Do I need to somehow create a separate umbrella header for the private headers?
You need to modify framework A
, So that it export a private module.
Create a private module map file in
A
project. This would be something like this:A/private.modulemap:
explicit module A.Private { // Here is the list of your private headers. header "Private1.h" header "Private2.h" export * }
In the "Build Settings" of framework
A
target, search "Private Module Map File" line, and make that:$(SRCROOT)/A/private.modulemap
Do not include
private.modulemap
file in "Compile Sources". That causes unnecessary warnings.Clean and Build framework
A
target.In framework B Swift files. you can import the private module like this:
import A import A.Private
这篇关于如何在Swift框架中导入私有框架头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!