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

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

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

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

更新:

这是一个Swift编译器错误。

更新2:

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


当前回答

我想我解决了这个问题。我有一些在框架中使用sqlite3的模型代码。在我的例子中,罪魁祸首是<sqlite3.h>。

问题是在我的Module/Module.h头文件中,我导入了一个导入<sqlite3.h>的公共头文件。解决方案是隐藏所有sqlite3_xxx类型,并确保它们 没有出现在任何公共场所。所有对sqlite3的直接引用都是私有或项目可见性。例如,我有一个公共单例,它挂有一些sqlite3_stmt指针。我把它们移动到一个单独的类中,现在它只是一个公共报头中的前向声明。现在我可以建造了。

顺便说一句,clang_allow_non_modular_incles_in_framework_modules设置不起作用。我试着在框架和相关项目中都设置它。这种变通是必要的,尽管我不确定为什么。

其他回答

我有Facebook 4.02 sdk和FBSDKCoreKit的具体问题。

我做了所有的步骤,但仍然错误关于非模块化头。我只从框架中拖放特定的头以构建阶段->头节。

然后在顶部的项目导航器上自动创建标题的副本。

我从构建阶段->头文件中删除了它,并删除了新文件,工作正常。

好像它被重置了。

对我来说,解决方案是去目标->构建设置->允许框架模块中的非模块化包含切换到YES!

下面是如何自动应用快速修复,这样你就不必更换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

Most commonly this error is caused by the chosen answer, yet I had this error appear once by accident when dragging framework files into my new project folder. I clicked to delete the frameworks but accidentally pressed to only 'Remove Reference' to the frameworks rather than to actually delete the files completely. At this point if I opened my project folder in Finder I saw files like 'CoreLocation' and 'AudioToolbox' there. Deleting these files from the project folder and cleaning the project fixed the issue.

在允许导入非模块化include之后,你可以尝试使用Objective-C Bridging头文件导入该模块:

#import <YandexMobileMetrica/YandexMobileMetrica.h>