Xcode -- finding dead methods in a project
Asked Answered
A

2

6

I am curious if there are any tools that provide partial solutions for this. It is a tricky problem because of performSelector . . . but a tool ought to at least be able to come up with candidates, making the human's job easier.

Alfonso answered 21/1, 2011 at 21:32 Comment(1)
I think #1457466 this post might be helpful to your question.Scutter
L
3

Using static analysis, it is impossible to detect functions/methods that are defined but not used due to dynamic nature of Objective-C. The only reasonable solution is to run a coverage using GCov or similar tool. Even then, you will have to make your program do everything possible in order to make sure that you do not strip out some feature that was just not used during testing.

Also, this script has some interesting thoughts on this.

Lemniscus answered 21/1, 2011 at 21:40 Comment(0)
O
1

Given the very verbose but descriptive method names often chosen in Objective-C programs, I find that doing a textual Find In Project is usually sufficient. I will usually just use the first part of a method name so as to avoid having to match method arguments. This will match normal method calls and use of @selector and NSSelectorFromString.

Of course, this won't work for very common method names or if you need the rest of the method name to disambiguate between many similar methods, but I find that to be a rare occurrence.

Oireachtas answered 22/1, 2011 at 15:17 Comment(1)
Yes, a textual find is often great. I would love a way to find all methods that are not called explicitly. It wouldn't be hard to sort out the few that get called in other ways.Alfonso

© 2022 - 2024 — McMap. All rights reserved.