xcode 重命名项目后,我找不到 <XCTest/XCTest.h>。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27324949/
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 06:19:40  来源:igfitidea点击:

After renaming project i get <XCTest/XCTest.h> not found.

iosxcoderenamexctest

提问by user3294722

I first duplicated my project before I renamed it. After the rename i'm getting

在重命名之前,我首先复制了我的项目。重命名后我得到

Lexical or Preprocessor Issue <XCTest/XCTest.h> not found. 

The error directs me to the myapptests.m file which calls to

该错误将我定向到 myapptests.m 文件,该文件调用

#import <XCTest/XCTest.h>

Also the next line

还有下一行

@interface SpyShotTests : XCTestCase

The "XCTestCase" is not hi-lighted in purple.

“XCTestCase”不是紫色的高亮。

Any tutorial i've seen has directed me to the Framework Search Paths in Build Settings - but the framework search path is exactly the same as the initial file and that file builds with no issues.

我见过的任何教程都将我定向到构建设置中的框架搜索路径 - 但框架搜索路径与初始文件完全相同,并且该文件构建没有问题。

回答by Derek Lee

I came across something similar and I'm wondering if my solution might be helpful.

我遇到了类似的问题,我想知道我的解决方案是否有帮助。

You may want to check that the file which is throwing the error is included in the appropriate Target Source's "Compile Sources". It's possible your file might not have been included. In my case it had been included with the project target and not with the test target. Since XCTest is only accessible with the Test Target, it wouldn't compile for me generating the error "XCTest/XCTest.h file not found".

您可能需要检查引发错误的文件是否包含在适当的目标源的“编译源”中。您的文件可能未包含在内。就我而言,它已包含在项目目标中,而不是包含在测试目标中。由于 XCTest 只能通过测试目标访问,它不会为我编译生成错误“XCTest/XCTest.h 文件未找到”。

Project Targets >> Build Phases >> Compile Sources:Making sure your test file is added as a compile source for the test target.

项目目标 >> 构建阶段 >> 编译源:确保您的测试文件被添加为测试目标的编译源。

You can fix this by either manually adding it to the "Compile Sources" as per the above image or you can remove the file from the project and re-add it, making sure to select the Test Target when you re-add: Adding a new file to the Test Target.

您可以通过按照上图手动将其添加到“编译源”中来解决此问题,也可以从项目中删除该文件并重新添加它,确保在重新添加时选择测试目标: 将新文件添加到测试目标。

In case it helps anyone else I came across this after moving a test case file (in the file system) and then re-adding it to my test project (right click, 'Add Files to "Project"...'). It turns out I wasn't adding the file to the Test target - I was just adding it to the Project Target.

如果它可以帮助其他人,我在移动测试用例文件(在文件系统中)然后将其重新添加到我的测试项目(右键单击,“将文件添加到“项目”...”)后遇到了这个问题。事实证明我没有将文件添加到测试目标 - 我只是将它添加到项目目标。

回答by 7stud

Xcode 7.2.1/Swift 2.1.1:

Xcode 7.2.1/Swift 2.1.1

When I created a new File, I chose iOS>Source>Swift File, and even though I checked the Test target, I still got an error on the import XCTestline:

当我创建一个新文件时,我选择了iOS>Source>Swift File,即使我检查了测试目标,我仍然import XCTest在线上出现错误:

error: cannot load underlying module for 'XCTest'

错误:无法为“XCTest”加载底层模块

To get rid of that error, when I created a new file I had to choose iOS>Source>Unit Test Case Class, and I accepted the defaults for everything else.

为了摆脱这个错误,当我创建一个新文件时,我必须选择iOS>Source>Unit Test Case Class,并且我接受了其他所有内容的默认值。