xcode 什么是我的“目标”以及如何向其中添加文件以进行单元测试?

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

What is my "Target" and how do I add a file to it for unit testing?

xcodeunit-testing

提问by annag

I'm trying to add my parser.m file to the target of my unit test (or, of my unit test file?), but I have no idea how.

我正在尝试将我的 parser.m 文件添加到我的单元测试(或我的单元测试文件?)的目标,但我不知道如何。

Here's an example of a page that indicates the necessity of using the target:

下面是一个页面示例,表明使用目标的必要性:

Undefined symbols for architecture i386 "_OBJC_CLASS_$_Appirater"

架构 i386 的未定义符号“_OBJC_CLASS_$_Appirater”

...and here's part of an answer from that page:

...这是该页面的部分答案:

I think, that you only added files to project, but not to target. Click on Appirater.m file in Project Navigator and set checkbox near to your target name in Target membership of File Inspector.

我认为,您只将文件添加到项目,而不是目标。单击 Project Navigator 中的 Appirater.m 文件,并在 File Inspector 的 Target 成员资格中设置靠近您的目标名称的复选框。

What I don't get from that answer is, "what checkbox?". Also, how do I know my target name? Where do I find 'Target membership'?

我从那个答案中没有得到的是,“什么复选框?”。另外,我怎么知道我的目标名称?我在哪里可以找到“目标会员”?

回答by rob mayoff

In Xcode, a target is usually an app - the app which you are creating! Occasionally it is a library or framework. (You can create other kinds of targets but don't worry about that.)

在 Xcode 中,目标通常是一个应用程序 - 您正在创建的应用程序!有时它是一个库或框架。(您可以创建其他类型的目标,但不用担心。)

You can use the File Inspector to add a file to a target, or remove a file from a target, or just check whether a file is a member of a target. Simply open a .mfile or a resource file (like an image or xib) in the editor pane, then select the File Inspector in the right-hand pane of the Xcode window and find the “Target Membership” section of the inspector. Check or uncheck the box next to your target. (You usually do notwant to add .hfiles to targets.) Here's a demonstration:

您可以使用文件检查器将文件添加到目标,或从目标中删除文件,或仅检查文件是否是目标的成员。只需.m在编辑器窗格中打开一个文件或资源文件(如图像或 xib),然后在 Xcode 窗口的右侧窗格中选择 File Inspector 并找到检查器的“Target Membership”部分。选中或取消选中目标旁边的框。(你通常希望添加.h文件到目标。)下面是一个演示:

add MyObject.m to addToTargetDemo target

将 MyObject.m 添加到 addToTargetDemo 目标

If you have multiple targets in the project, each target appears in the “Target Membership” section. Each source file can be a member of any combination of the targets, depending on your needs. For example, if you are creating separate iPhone and iPad apps (instead of a universal app) which share most of their code and resources, you can create a project with two targets. One target is the iPhone app and the other target is the iPad app. You add the common source files to both targets. You add the iPhone-specific .mfiles and resource files to the iPhone app target only. You add the iPad-specific .mfiles and resource files to the iPad app target only.

如果项目中有多个目标,则每个目标都会出现在“目标成员资格”部分中。每个源文件都可以是目标的任意组合的成员,具体取决于您的需要。例如,如果您正在创建共享大部分代码和资源的单独 iPhone 和 iPad 应用程序(而不是通用应用程序),您可以创建一个具有两个目标的项目。一个目标是 iPhone 应用程序,另一个目标是 iPad 应用程序。您将公共源文件添加到两个目标。您.m只能将 iPhone 特定的文件和资源文件添加到 iPhone 应用程序目标。您.m只能将 iPad 特定的文件和资源文件添加到 iPad 应用程序目标。