views:

68

answers:

4

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?

+1  A: 

Searching the project with the class name might be an option, thought it may not be the best solution. Specially it might be time consuming when you have many classes.

taskinoor
+1  A: 

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.

w.m
The target column may be misleading, in that it only considers the active target. If the class is not used in the active target but is used in another target, the target column will have no checkmark even though it is being used.
Peter Hosey
That's why I suggested to try to find files that don't have a check in any of the targets. Of course, this won't be much fun if you have a lot of targets..
w.m
A: 

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.

Justin
A: 

This is a tricky question due to how dynamic objective-c is as you can never guarantee that a class is not going to be used.

Consider if you generate a class name and a selector at run time and then look up that class, instantiate that class and then call a method on that newly created object using that newly created selector. No where in your code do you explicitly name and instantiate that object but you are able to use it anyways. You could get that class name and selector name from anywhere outside of your code, even from some data from a server some where. How would you ever know which class is not going to be used? Because of this there are no tools that are able to perform what you are requesting.

djdrzzy