简体   繁体   English

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

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

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...导入文件很容易,不用勾选所有框...

许多目标

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?也许是剧本?

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. * hack 在某种意义上取决于 Xcode 文件格式的实现细节。

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.如果您选中一个目标,则所有选定的文件都将添加到该目标。

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 文件进行比较。

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.在 Xcode 8 中,列出 Target -> Build Phases -> Compile Sources 中的文件给出了每个目标的文件列表,但没有简单的方法可以找到丢失的文件。 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.在对两个目标执行此操作后,将其放入单独的文件夹中,然后可以删除重复项,直到每个文件夹中只剩下另一个目标中丢失的文件。

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.这不是一个有效或优雅的解决方案,但它完成了工作。

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.将其粘贴到差异程序中,选择另一个目标并重复。

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

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 的实际目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM