如何在 Xcode 中找到所有不是目标成员的文件

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

How do I find all files in Xcode that are NOT a member of a target

iphoneobjective-ciosxcode

提问by Robert

One of the most common issues I have with multiple targets is forgetting to add a file to all targets. Its easy to import a file and not tick all the boxes...

我对多个目标最常见的问题之一是忘记向所有目标添加文件。导入文件很容易,而不是勾选所有框......

Many Targets

许多目标

In build phases there is a 'compile sources' view which is a list of files compiled for each target. However there seams to be no easy way to compare targets to see what files are in one but not the other.

在构建阶段,有一个“编译源”视图,它是为每个目标编译的文件列表。然而,要比较目标以查看哪些文件在一个文件中而不是另一个文件中,还没有一种简单的方法。

Is there a way to find the files that are NOT a member of a particular target? A script perhaps?

有没有办法找到不是特定目标成员的文件?也许是脚本?

采纳答案by bames53

I don't know of a way to script it, but for a file you can view a list of all targets with the associated targets checked, and you can check or uncheck targets from that list.

我不知道编写脚本的方法,但对于文件,您可以查看所有目标的列表,并选中相关联的目标,您可以从该列表中选中或取消选中目标。

Open the Utilities pane and select the File Inspector. Then select a file and the related targets will be in the Target Membership area of the File Inspector.

打开实用程序窗格并选择文件检查器。然后选择一个文件,相关目标将在文件检查器的目标成员资格区域中。

You can even select multiple files and the targets that are associated to some but not all the selected files will be marked with '-'. If you check a target then all the selected files will be added to that target.

您甚至可以选择多个文件,并且与某些但并非所有选定文件相关联的目标将标有“-”。如果您选中一个目标,则所有选定的文件都将添加到该目标中。

回答by Eli Manjarrez

Assuming your MyProject.xcodeproj is in your working directory, and all your sources are in or below your working directory, you could use a hack* like this to look for .m files that are not part of any target:

假设您的 MyProject.xcodeproj 在您的工作目录中,并且您的所有源代码都在您的工作目录中或下方,您可以使用这样的 hack* 来查找不属于任何目标的 .m 文件:

find . -name "*.m" -exec basename '{}' \; | xargs -I '{}' sh -c 'grep "{} in Sources" MyProject.xcodeproj/project.pbxproj > /dev/null; echo "$?\c"; echo " {}"' | grep "^1"

Once you remove the files from the project, you can remove them -- and other objc source files that are no longer referenced from your project -- from your git repo using this similar script:

从项目中删除文件后,您可以使用以下类似脚本从 git 存储库中删除它们——以及不再从项目中引用的其他 objc 源文件:

find . -name "*.[hm]" -exec basename '{}' \; | xargs -I '{}' sh -c 'grep {} MyProject.xcodeproj/project.pbxproj > /dev/null; echo "$?\c"; echo " {}"' | grep "^1" | cut -c3- | xargs -I '%' find . -name '%' -exec git rm '{}' \;

* hack in the sense that it depends on implementation details of the Xcode file format.

* 从某种意义上说,它取决于 Xcode 文件格式的实现细节。

回答by Justin

In Xcode 8, listing the files from the Target -> Build Phases -> Compile Sources gave a list of files for each target but no easy way to find the missing ones. Selecting all files and copying them allows copies of the physical files to be pasted into a temporary directory. After doing this with both targets, into separate folders, duplicates can then be deleted until only files missing from the other target are left in each folder.

在 Xcode 8 中,从 Target -> Build Phases -> Compile Sources 列出文件为每个目标提供了一个文件列表,但没有简单的方法来找到丢失的文件。选择所有文件并复制它们允许将物理文件的副本粘贴到临时目录中。在对两个目标执行此操作后,将其放入单独的文件夹中,然后可以删除重复项,直到每个文件夹中只剩下另一个目标中丢失的文件。

I've just had a "this class is not key value coding-compliant for the key" crash caused by a file not being included in a target so I had to find the missing files. Not an efficient or elegant solution but it got the job done.

我刚刚遇到了“这个类不是键值编码兼容的键”崩溃,原因是文件未包含在目标中,所以我必须找到丢失的文件。不是一个有效或优雅的解决方案,但它完成了工作。

回答by Confused Vorlon

I built a tool which lets you extract what files are in targets

我构建了一个工具,可以让您提取目标中的文件

https://github.com/ConfusedVorlon/ProjectFileTool

https://github.com/ConfusedVorlon/ProjectFileTool

You could compare this with a file search for .m files within your project directory.

您可以将此与在项目目录中搜索 .m 文件的文件进行比较。

回答by Fernando Martínez

Xcode assembles some env variables and one of them has the dir you want to look for:

Xcode 会组合一些 env 变量,其中一个包含您要查找的目录:

LINK_FILE_LIST_normal_x86_64, for x86_64 target, it point to the LinkFileList, but from basedir you can get the actual dir with FileLists you may want.

LINK_FILE_LIST_normal_x86_64, 对于 x86_64 目标,它指向LinkFileList,但从 basedir 中,您可以使用您可能想要的 FileLists 获取实际目录。

回答by arsenius

If you don't know which files you added to a target, you can go to Build Phases->Compile Sources (or whatever section you have differences in). Then select everything and hit copy. Paste this into a diff program, select the other target and repeat.

如果您不知道将哪些文件添加到目标,您可以转到 Build Phases->Compile Sources(或您有不同之处的任何部分)。然后选择所有内容并点击复制。将此粘贴到差异程序中,选择另一个目标并重复。

回答by Jasper Blues

I don't know a (completely) quick and easy way, but if you were after a script, I have a library that could do this here: https://github.com/jasperblues/XcodeEditor

我不知道(完全)快速简便的方法,但是如果您使用脚本,我有一个可以在此处执行此操作的库:https: //github.com/jasperblues/XcodeEditor