13

我的 XCode 项目有所增长,我知道其中有不再使用的类文件。有没有一种简单的方法可以找到所有这些并删除它们?

4

4 回答 4

4

If the class files just sit in your project without being part of a target, just click on the project itself in the tree view, so you see all files in the table. Make sure you see the "Target" column in the table view, iterate through your targets and find the files that don't have a check anywhere -> they are no longer compiled.

But if you still compile the classes and they are no longer used, that case is a bit more difficult. Check out this project

http://www.karppinen.fi/analysistool/#dependency-graphs

You could create a dependency graph and try to find orphaned classes that way.

Edit: Link went dead, but there still seem to be projects of Objective-C dependency graphs around, for example https://github.com/nst/objc_dep

于 2010-10-08T09:40:18.283 回答
2

这是一个棘手的问题,因为objective-c 是多么动态,因为您永远无法保证不会使用某个类。

考虑是否在运行时生成类名和选择器,然后查找该类,实例化该类,然后使用该新创建的选择器在该新创建的对象上调用方法。您在代码中的任何位置都没有明确命名和实例化该对象,但无论如何您都可以使用它。您可以从代码之外的任何地方获取该类名称和选择器名称,甚至可以从某处服务器的某些数据中获取。你怎么知道哪个类不会被使用?因此,没有工具能够执行您的请求。

于 2010-10-08T15:44:38.020 回答
2

如果它们是 C 或 C++ 符号,那么您可以让链接器为您完成工作。

如果您要删除 objc 符号,请尝试重构类名(例如重命名类),并预览它出现的依赖项。如果您引用类/选择器/等。那么通过字符串......它可能没有那么有效。不幸的是,您通常还必须手动测试,以验证删除一个类不会破坏任何东西。请记住,资源(如 xibs)也可能引用/加载 objc 类。

于 2010-10-08T09:56:59.217 回答
1

使用类名搜索项目可能是一种选择,认为它可能不是最佳解决方案。特别是当你有很多课程时可能会很耗时。

于 2010-10-08T06:59:55.030 回答