如何使 Swift 框架子模块真正私有? [英] How to make a Swift framework submodule really private?

查看:24
本文介绍了如何使 Swift 框架子模块真正私有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了另一个问题,其中提供了有关问题和可能的解决方案的更多详细信息.似乎存在一个已知错误,需要在未来进行改进.

I've found another question which brings more details regarding the problem and possible solutions. It seems like there is a known bug which is a subject for future improvements.

基于 iOS Swift 的目标 C 类动态框架

我正在 Swift 中开发一个框架,并且在框架内使用了一些 Objective-C 代码.到目前为止,我的模块映射如下所示:

I'm developing a framework in Swift and I'm using some Objective-C code inside the framework. So far my module map looks like this:

framework module MyModule {
    umbrella header "MyModule-umbrella.h"

    export *

    explicit module Private {
        header "MyTools.h"
    }
}

我担心的是 MyTools.h 中的所有 API 在框架外都是可见的:例如,如果您使用 Cocoapods 安装框架,那么您import MyModule进入您的应用程序(不是 MyModule.Private),您可以访问 MyTools.h,这是不需要的和多余的.有没有办法让 MyTools 在框架外不可见?

My concern is that all the APIs from MyTools.h are visible from outside the framework: for example, if you install the framework using Cocoapods, then you import MyModule into your application (not MyModule.Private), you are able to access MyTools.h which is not desirable and redundant. Is there any way to make MyTools invisible from outside the framework?

附注.我使用 Cocoapods 分发框架,这是我的 podspec(最重要的部分):

PS. I use Cocoapods to distribute the framework, here is my podspec (the most significant part):

s.module_map    = 'Pod/MyModule.modulemap'
s.frameworks    = 'CoreData', 'CoreTelephony', 'SystemConfiguration'
s.resources     = 'Pod/Classes/MessageStorage/*.xcdatamodeld'
s.public_header_files = 'Pod/Classes/**/*.h'
s.private_header_files = 'Pod/Classes/MyTools/**/*.h'
s.source_files  = 'Pod/Classes/**/*.{h,m,swift}'

PSS.我的伞头不导入 MyTools.h

PSS. My umbrella header does not import MyTools.h

PSSS.只是试图从主模块中排除标题:

PSSS. Just tried to exclude the header from the main module:

framework module MyModule {
    umbrella header "MyModule-umbrella.h"

    export *
    exclude header "MyTools.h"

    explicit module Private {
        header "MyTools.h"
    }
}

运气不好.

推荐答案

我发现了另一个问题,该问题提供了有关问题和可能的解决方案的更多详细信息(尽管不起作用).似乎存在一个已知错误,需要在未来进行改进.

I found another question which brings more details regarding the problem and possible solutions (which don't work though). It seems like there is a known bug which is a subject for future improvements.

基于 iOS Swift 的目标 C 类动态框架

这篇关于如何使 Swift 框架子模块真正私有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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