如何在Swift框架中导入私有框架头文件? [英] How to import private framework headers in a Swift framework?

查看:1329
本文介绍了如何在Swift框架中导入私有框架头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Objective-C框架(框架A),暴露一些公共和一些私有头。公共头部也在框架的伞头中声明。我有一个与Objective-C框架链接的第二个Swift框架(框架B)。



现在,如果我想导入A的公共头部做一个 import A



但是如何导入私有头?



我知道桥接头不是一个选项,因为不支持框架。我需要以某种方式为私有头创建一个单独的伞头吗?

解决方案

你需要修改框架 A ,以便导出私有模块。


  1. 创建 A 项目中的http://clang.llvm.org/docs/Modules.html#private-module-map-files\">私有模块映射文件。这将是这样:



    A / private.modulemap

     显式模块A.Private {

    //这是你的私有头文件的列表。
    headerPrivate1.h
    headerPrivate2.h

    export *
    }


  2. 在框架 A 目标的Build Settings中,搜索Private Module Map File并使其:

      $(SRCROOT)/A/private.modulemap 


  3. 不要在编译源中包含 private.modulemap 文件。这会导致不必要的警告。


  4. 清洁和构建框架 A >

  5. 在框架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.

  1. 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 *
    }
    

  2. In the "Build Settings" of framework A target, search "Private Module Map File" line, and make that:

    $(SRCROOT)/A/private.modulemap
    

  3. Do not include private.modulemap file in "Compile Sources". That causes unnecessary warnings.

  4. Clean and Build framework A target.

  5. In framework B Swift files. you can import the private module like this:

    import A
    import A.Private
    

这篇关于如何在Swift框架中导入私有框架头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆