ios 在 Xcode 中查找未使用的文件

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

Finding unused files in Xcode

iosxcode

提问by JDx

I've recently started work on a new app which is basically a copy of a previous app I made, with a few changes. To make this new app I've copied the old app and removed some stuff that isn't needed.

我最近开始开发一个新应用程序,它基本上是我之前制作的应用程序的副本,但做了一些更改。为了制作这个新应用程序,我复制了旧应用程序并删除了一些不需要的东西。

I'm wondering, is there any way to tell which class files are being used in Xcode? Or any tips on how to find unused files?

我想知道,有什么方法可以判断 Xcode 中使用了哪些类文件?或者有关如何查找未使用文件的任何提示?

采纳答案by WDUK

There isn't any functionality like this built into Xcode, but the issue of unused classes/files etc isn't as simple as one may think.

Xcode 没有内置任何这样的功能,但是未使用的类/文件等问题并不像人们想象的那么简单。

People have created scripts to try and determine unused files. I have used the script located here, which searches through all your source files, and tries to pair up the resource files. The script also tries to check for source files not included within your project.

人们已经创建了脚本来尝试确定未使用的文件。我使用了位于此处脚本,它搜索所有源文件,并尝试配对资源文件。该脚本还尝试检查未包含在您的项目中的源文件。

The reason its not so trivial is that Obj-C is a very dynamic language; a lot of things are determined at run-time. As such, it sometimes can be tricky to figure out unused files statically. For example, an image name might be determined on the fly depending on user input.

之所以不是那么简单,是因为 Obj-C 是一种非常动态的语言;很多事情都是在运行时确定的。因此,有时很难静态地找出未使用的文件。例如,可以根据用户输入即时确定图像名称。

I don't know how big your application is, but you could try a dependency graph, and check for orphan classes. See this blog poston some more information.

我不知道您的应用程序有多大,但是您可以尝试使用依赖关系图并检查孤立类。有关更多信息,请参阅此博客文章

回答by Wilmar

The AppCodeIDE from Jetbrains has some very decent code inspection functions. It can point out unused classes and other resources, and claims to be fully Xcode compatible.

Jetbrains的AppCodeIDE 有一些非常不错的代码检查功能。它可以指出未使用的类和其他资源,并声称与 Xcode 完全兼容。

回答by Vito Ziv

See the useful tool. A Mac app for checking Xcode projects for unused resources http://jeffhodnett.github.io/Unused/

查看有用的工具。用于检查 Xcode 项目中未使用资源的 Mac 应用程序 http://jeffhodnett.github.io/Unused/

回答by Stanislav Pankevich

This tool finds unused imports/classes: fui.

此工具查找未使用的导入/类:fui

From the README page:

从自述页面:

Find unused Objective-C imports.

查找未使用的 Objective-C 导入。

回答by Ali

Also see this shell scripts http://mfaizanshaikh.wordpress.com/2012/12/17/how-to-remove-unused-images-from-xcode-project/

另请参阅此 shell 脚本http://mfaizanshaikh.wordpress.com/2012/12/17/how-to-remove-unused-images-from-xcode-project/

Basically the shell script below, finds all the pngfiles in your project that are not used in any of the xibfiles. Of course if you have used the pngfile in other ways (storyboards, load in the code), this script will still show them as unused.
for reference I paste the scripts here as well:

基本上,下面的 shell 脚本会查找png项目中未在任何xib文件中使用的所有文件。当然,如果您png以其他方式使用过该文件(故事板、加载代码),该脚本仍会将它们显示为未使用。
作为参考,我也在这里粘贴了脚本:

#!/bin/sh
PROJ=`find . -name '*.xib' -o -name '*.[mh]'`

for png in `find . -name '*.png'`
do
    name=`basename $png`
    if ! grep -q $name $PROJ; then
        echo "$png is not referenced"
    fi
done

回答by siburb

There's an app called Slender by Martiancraft that is good for suggesting potentially unused images.

Martiancraft 有一个名为 Slender 的应用程序,可以很好地建议可能未使用的图像。

http://martiancraft.com/products/slender.html

http://martiancraft.com/products/slender.html

I believe that Faux Pas does something similar for class files, but I will check. That app does also look for unused methods, translations and resources.

我相信 Faux Pas 对类文件做了类似的事情,但我会检查。该应用程序还会查找未使用的方法、翻译和资源。

http://fauxpasapp.com/rules/#rule-UnusedResource

http://fauxpasapp.com/rules/#rule-UnusedResource

I haven't used either app recently, but can remember being impressed with both previously.

我最近没有使用过这两个应用程序,但我记得以前对这两个应用程序印象深刻。