XCode - iOS - <OCMock/OCMock.h> 文件未找到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25716580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:29:48  来源:igfitidea点击:

XCode - iOS - <OCMock/OCMock.h> file not found

iosxcodeocmock

提问by Vince613

I Have an iOS application that I am trying to add OCMock to in order to better unit test it. I've followed the instruction on ocmock.org as well as instructions I've found in other places but still I cannot get my test code to compile.

我有一个 iOS 应用程序,我试图将 OCMock 添加到其中以便更好地对其进行单元测试。我已经按照 ocmock.org 上的说明以及我在其他地方找到的说明进行了操作,但仍然无法编译测试代码。

Here's what I've done

这是我所做的

Added the source code to my project directory enter image description here

将源代码添加到我的项目目录中 在此处输入图片说明

Create the groups in my project to mimic my file system enter image description here

在我的项目中创建组来模仿我的文件系统 在此处输入图片说明

I selected the option to add to my test targets so the framework was added appropriately as well as the Library Search Path enter image description hereenter image description here

我选择了添加到我的测试目标的选项,以便适当地添加框架以及库搜索路径 在此处输入图片说明在此处输入图片说明

Then I manually added the headers to the Header Search Path enter image description here

然后我手动将标题添加到标题搜索路径 在此处输入图片说明

And added the -ObjC linker flag enter image description here

并添加了 -ObjC 链接器标志 在此处输入图片说明

Then when I go to import the header file, I get the file not found error enter image description here

然后当我去导入头文件时,我得到文件未找到错误 在此处输入图片说明

Any ideas what I am missing here???

任何想法我在这里缺少什么???

回答by Jeffery Thomas

You have the search path test/libraries/OCMock. Then you have #import <OCMock/OCMock.h>.

你有搜索路径test/libraries/OCMock。那么你有#import <OCMock/OCMock.h>

This fails because there is no file test/libraries/OCMock/OCMock/OCMock.h.

这将失败,因为没有文件test/libraries/OCMock/OCMock/OCMock.h

You use the search path test/libraries, or you can create a prefix directory to hold OCMockand have the search path point at that.

您可以使用搜索路径test/libraries,或者您可以创建一个前缀目录来保存OCMock并让搜索路径指向该目录。

I generally have a directory with the library name and version number before the actually directory.

我通常在实际目录之前有一个包含库名称和版本号的目录。

The directory test/libraries/OCMock-X.X.Xcould contain the OCMockdirectory. That way the search path still be more specific: test/libraries/OCMock-X.X.Xand you still use OCMock/OCMock.has the include.

目录test/libraries/OCMock-X.X.X可以包含OCMock目录。这样搜索路径仍然更具体:test/libraries/OCMock-X.X.X并且您仍然使用OCMock/OCMock.h作为包含。

回答by janineanne

One more thing to check, for anyone else having this problem - I copied OCMock from one project to another and everything lookedright, but it wasn't finding the include file. It turned out that even though I had the right groups in Xcode, the files had all been dumped into one directory. I needed to create folders on disk and associate them with the groups in Xcode. The accepted answer here clued me in to what was wrong (though as is often the case, in hindsight it should have been obvious).

还有一件事要检查,对于其他遇到此问题的人 - 我将 OCMock 从一个项目复制到另一个项目,一切看起来都正确,但没有找到包含文件。结果是,即使我在 Xcode 中设置了正确的组,文件也已全部转储到一个目录中。我需要在磁盘上创建文件夹并将它们与 Xcode 中的组相关联。这里接受的答案让我知道出了什么问题(尽管通常情况下,事后看来它应该是显而易见的)。