现在我想把我的ObjC框架迁移到Swift,我得到了以下错误:

include of non-modular header inside framework module 'SOGraphDB'

引用是一个头文件,它只是定义了一个协议,我在一些类中使用这个头文件来使用这个协议。

这似乎与模块特性有关,但目前不太清楚如何修复,你知道解决方案吗?

更新:

这是一个Swift编译器错误。

更新2:

一个快速的解决方法(但不能解决根本原因)是将以下设置设置为yes: clang_allow_non_modular_incles_in_framework_modules = yes


当前回答

我尝试了我在这个线程上找到的所有可能的解决方案,设置目标->构建设置->允许框架模块中的非模块化包含切换到YES!等等。

但是什么都不管用。

当我通过评论use_frameworks安装pods时,我开始得到这个错误!,因为我想有一个静态库的豆荚。

原因Swift编译器抛出(在Xcode 13)这个错误,因为我正在导入私有框架头#导入“TFLTensorFlowLite.h” 在公共.h文件中,所以我在.m文件中导入了它,如下面的截图所示,它停止了Swift编译器抛出这个错误(注意我的框架有Objective c和Swift代码)

其他回答

我尝试了我在这个线程上找到的所有可能的解决方案,设置目标->构建设置->允许框架模块中的非模块化包含切换到YES!等等。

但是什么都不管用。

当我通过评论use_frameworks安装pods时,我开始得到这个错误!,因为我想有一个静态库的豆荚。

原因Swift编译器抛出(在Xcode 13)这个错误,因为我正在导入私有框架头#导入“TFLTensorFlowLite.h” 在公共.h文件中,所以我在.m文件中导入了它,如下面的截图所示,它停止了Swift编译器抛出这个错误(注意我的框架有Objective c和Swift代码)

导入Parse框架时遇到了这个问题。我能解决这个问题的唯一方法是放弃我上次提交后所做的所有更改(简单地删除框架并清理项目不起作用),并再次添加Parse(在重新下载SDK之后)及其所需的其他框架。

下面是如何自动应用快速修复,这样你就不必更换Pods了。在每个pod安装后手动Xcodeproj。

将这个片段添加到Podfile的末尾:

post_install do |installer|
  installer.pods_project.build_configuration_list.build_configurations.each do |configuration|
    configuration.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
  end
end

迅速:

1. 修改你的Xcode项目和目标的构建设置如下所示:

允许非模块包含在框架模块中

Enable Bitcode:是

2. 使用当前最新版本的GoogleMaps iOS SDK(使用CocoaPods获取):

谷歌地图 (1.10.4)

3.注释有问题的导入:

//import GoogleMaps

4. 创建或修改桥接头文件,添加有问题的导入:

[你的Xcode项目名称]-Bridging-Header.h

// Use this file to import your target's public headers 
// that you would like to expose to Swift.
#import <GoogleMaps/GoogleMaps.h>

5. 清理并重新构建Xcode项目。

我也想补充一下我在这个问题上的经验。

总结一下:

@ambientlight的回答很棒,它解决了大部分问题。 允许非模块化报头是另一种解决方案(参见上面的一些答案)。 将框架的头标记为公共的(只有那些您想要公开的),并将它们导入到伞形头中。

以下是我对上述答案的2个补充:

carefully check the imports in your project for headers which import your frameworks directly in them (instead of using forward declaration, if possible) -- it is not a good practice to include a header file inside another header file; sometimes this causes a problems, because if not done properly this may lead to multiple include-ing of one header and create linker issues. UPDATE: make sure that the architectures of the library and that of the target that you want to link it to match. and lastly, after doing all of the above, I still kept bumping onto that error. So I dug a little more and found (in the apple developer forums, but I lost the link :( ) that if you include the headers in the umbrella header not like this <framework/headerName.h>, but only like this "headerName.h", the problem goes away.

我尝试了最后一个,到目前为止我还没有遇到过这个问题,但是我怀疑这个解决方案只有在你应用了一些顶部的答案时才有效(注意:它们并不都相互兼容,例如,模块方法和允许非模块头包含)。