Xcode 轻松地将多个文件添加到一个目标

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

Xcode easily add multiple files to a target

xcode

提问by bandejapaisa

I've created a new target for unit tests in Xcode 4.2, and obviously i need to bring in certain application files into that target. But there is a lot, and it seems cumbersome to click each .m file then click TargetMembership and tick the new target box.

我在 Xcode 4.2 中为单元测试创​​建了一个新目标,显然我需要将某些应用程序文件引入该目标。但是有很多,单击每个.m文件然后单击TargetMembership并勾选新目标框似乎很麻烦。

Is there an easier way to do this in Xcode that i'm missing?

有没有更简单的方法可以在 Xcode 中做到这一点,但我缺少它?

Thanks

谢谢

回答by bandejapaisa

I though't i'd return to this with an improved answer. It's still difficult to do this via Xcode main interface, as if you filter for .m and try and do CMD-A to select all, it selects the folders too, so you can't add these to the target.

我想我不会用改进的答案来回答这个问题。通过 Xcode 主界面执行此操作仍然很困难,就像您过滤 .m 并尝试执行 CMD-A 以全选一样,它也会选择文件夹,因此您无法将这些添加到目标中。

However, if you go to Project Settings > Build Phases > Compile Sources. You can click the + button, filter .m files, and you can CMD-A to select all here.

但是,如果您转到“项目设置”>“构建阶段”>“编译源”。可以点击+按钮,过滤.m文件,这里可以CMD-A全选。

This works.

这有效。

screenshot

截屏

回答by user1050660

If the files are all in a single directory, delete the directory from the project (remove reference only), then re-add it. Xcode will ask you which targets you want the files to be added to when you re-add it.

如果文件都在一个目录中,请从项目中删除该目录(仅删除引用),然后重新添加它。当您重新添加文件时,Xcode 会询问您希望将文件添加到哪些目标。

回答by zaph

Select all the .mfiles in the "Project Editor" (cmd-1), show the "Utilities View" (opt-cmd-0) and click the new target in "Target Membership". Be careful not to select files that do not belong to a project such as .hfiles.

选择.m“项目编辑器”( cmd-1)中的所有文件,显示“实用程序视图”( opt-cmd-0) 并单击“目标成员资格”中的新目标。注意不要选择文件等不属于项目的.h文件。

回答by justin

create a static or dynamic library, to which both executables link.

创建一个静态或动态库,两个可执行文件都链接到该库。

回答by Erdem Gezer

If you duplicate and existing target instead of creating a new one from scratch, all the existing files will be a member of the new(duplicated) target as well.

如果您复制现有目标而不是从头开始创建新目标,则所有现有文件也将成为新(复制)目标的成员。

回答by Kreeble Song

In 2016 you can now use both an AppTest and LogicTest target so you don't have to fiddle around with target settings.

在 2016 年,您现在可以同时使用 AppTest 和 LogicTest 目标,因此您不必摆弄目标设置。

You don't need to add any files to the AppTest target since it will have access to all main target files, and put pure logic tests in LogicTest.

您不需要向 AppTest 目标添加任何文件,因为它可以访问所有主要目标文件,并将纯逻辑测试放在 LogicTest 中。

回答by Dima Gershman

In Xcode 10

Xcode 10 中

You can also select multiple files in Project navigator and then, in the "Inspectors" right side pane you can modify Target Membership:

您还可以在项目导航器中选择多个文件,然后在“检查器”右侧窗格中,您可以修改目标成员资格:

Target Membership

目标会员