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

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

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

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

更新:

这是一个Swift编译器错误。

更新2:

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


当前回答

#import "MyOtherFramework.h"

Do

#import <MyOtherFramework/MyOtherFramework.h>

其他回答

我知道这是一个老问题,但我也有同样的问题,上面没有任何东西能帮助我。所以我希望我的回答能对别人有所帮助。 在我的情况下,问题是在ALWAYS_SEARCH_USER_PATHS设置。当它被设置为NO时,项目建立并工作正常。但只要其中一个pod要求将其设置为YES,我就会收到一个错误

包括非模块化的头在框架模块内

在喝了几杯咖啡和一整天的研究之后,我发现根据Xcode 7.1 Beta 2发布说明的已知问题:

如果你得到一个错误声明“包含非模块头在框架模块” 之前编译的框架,确保“Always Search User Paths” 构建设置设置为“No”。仅由于遗留原因,默认为“Yes”。(22784786)

虽然我使用的是XCode 7.3,但似乎这个bug还没有修复。

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

总结一下:

@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.

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

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

#import <YandexMobileMetrica/YandexMobileMetrica.h>

我解决了它从框架中删除模块文件夹。

使用finder浏览到应用程序项目中显示的框架位置 进入Test.framework文件夹(在上面的例子中,它将是SOGraphDB.framework) &删除模块文件夹。 清洁和重新构建应用程序,它将解决问题。

当我在一个项目中包含我自己的框架时,我就遇到了这个问题。修正了将sqlite3.h的所有导入都放在。m文件中,而不是公共的。h文件中。我认为其他库也会在Xcode中标记出类似的问题。