Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find and remove unused class files from a project

My XCode project has grown somewhat, and I know that there are class files in there which are no longer being used. Is there an easy way to find all of these and remove them?

like image 898
node ninja Avatar asked Oct 08 '10 06:10

node ninja


People also ask

How do I find unused classes in Eclipse?

UCDetector (Unecessary Code Detector) is a Open Source eclipse PlugIn Tool to find unecessary (dead) public java code. It also tries to make code final, protected or private. Caveat: Cid mentions in the comments: UCDetector shall not work if there are interface implementations which will be known only at runtime.

How do I find unused files in Xcode?

xcutility is a tool to find and delete unused files from Xcode projects. It recursively searches through a path to find all of the path's Xcode projects and files, and will tell you which files are not referenced or built in any of your Xcode projects.


2 Answers

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

like image 122
w-m Avatar answered Oct 03 '22 02:10

w-m


if they are C or C++ symbols, then you can just let the linker do the work for you.

if you're looking to remove objc symbols, then try to refactor the class name (e.g. to rename the class), and preview the dependencies that it turns up. if you reference classes/selectors/etc. by strings then... it may not be so effective. unfortunately, you often have to also test manually, to verify that removing a class does not break anything. remember that resources (like xibs) may reference/load objc classes as well.

like image 28
justin Avatar answered Oct 03 '22 01:10

justin