我目前在Swift编码,我有一个错误:

没有这样的模块

但我不明白,因为这个模块在我的项目中,在“链接框架和库”和“嵌入式二进制文件”中声明。

框架是在Objective-C中,所以我为它写了一个桥标头。

请问,如何让Xcode识别框架?


当前回答

几天前我也遇到了同样的错误。下面是我解决这个问题的方法:

错误是“模块未找到”

Create Podfile in your root project directory Install cocoapods (a dependency manager for Swift and iOS projects) Run pod install Go to Project Build Settings: Find Objective-c bridging Header under Swift compiler - Code Generation (If you don't find Swift compiler here, probably add a new Swift file to the project) Drag and drop the library header file from left side to bridging header (see image attached) Create a new bridging header file: e.g TestProject-Bridging-Header.h and put under Swift Compiler → Objective-C Generated Interface Header Name (ref, see the image above) In TestProject-Bridging-Header.h file, write #import "Mixpanel/Mixpanel.h" In your Swift file the code should be: Import Mixpanel (i.e name of library)

这是所有。

其他回答

确保Scheme中的“在构建中查找隐式依赖项”选项是打开的!

大多数其他答案都是针对CocoaPods或迦太基用户的。如果你不使用这些,但只是想在你的项目中删除一个框架并链接它,它将需要在框架搜索路径中。

系统框架已经在搜索路径(即/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/ sdk/ iPhoneOS${version}.sdk/ system /Library/ frameworks /)。如果您试图使用的文件不在此路径中,则需要将它们的路径添加到Build Settings中的FRAMEWORK_SEARCH_PATHS中。


为什么XCode不知道在哪里找到它,即使你左边面板上的框架在右边面板的标识和类型中列出了一个位置和完整的路径?那我不知道。

如果这只是一个简单的项目,没有可可足类,就像我做的, 你可以尝试移动你的框架到你的项目目录和重新链接。 我把它放在桌面上,但是链接和“导入我的框架”犯了一个错误。在将其移动到项目目录并再次链接后,它工作了。

在我的例子中: 该问题只发生在Xcode 12.4,而不是Xcode 13。 测试目标的一个框架在我为arm64模拟器支持重新构建框架后给出了这个错误(在XCFramework格式)。我通过更新框架搜索路径中的路径来修复它

"$(SRCROOT)/Carthage/Build/WireTesting.xcframework/ios-x86_64-simulator" 

to

"$(SRCROOT)/Carthage/Build/WireTesting.xcframework/ios-arm64_x86_64-simulator" 

如果工作区中有多个项目,则需要:

向所有项目添加新配置 产品->清洁 删除派生数据 终端吊舱安装 构建您的项目。