Injectios
Injectios

Reputation: 2797

Detecting unused methods iOS

Very simple question and hopefully isn't duplicated :).

The situation is following:

Project has been developing more then a year and by many developers.
From time to time I'm facing with unused methods (which are defined in .h and .m) obviously I'm not getting any warnings.

This is not critical, but I would like to have project cleared from all unnecessary staff. Of course I can search for all methods and define which are unused in project but I wonder if there is more elegant way?!

Thanks

Upvotes: 9

Views: 4709

Answers (3)

azsromej
azsromej

Reputation: 1629

A quick way to check while browsing your source code is the View > Standard Editor > Show Related Items menu (shortcut key: ^1). Place your cursor within a method body and then view the Callers.

enter image description here

Upvotes: 12

TomG103
TomG103

Reputation: 312

Might I suggest adding an NSLOG to these methods. For example, if you have a View Controller called Home, you can go into the .m file for the Home View Controller and at the top of the function, write the following:

NSLOG(@"Method 1, has 3 buttons);

then watch the readout as you progress through the actions on that View Controller. The log should say something that would best describe the method in question. Step 2 would be to take the methods that you feel aren't showing up on the output and comment them out. That can be done by highlighting the method and then hitting Command + '/' on the keyboard. This will place '//' in front of each highlighted line commenting it out. Test your view controller again and if still no errors, you can delete that method. That's a free way to do it, but it does take some time.

Upvotes: -3

EricD
EricD

Reputation: 551

AppCode (http://www.jetbrains.com/objc) can tell you if a method or an import is unused. It's works in real time, but you can also inspect a whole project (menu code > inspect Code)

enter image description here

I don't think xCode can do it. AppCode is not free, but it has a trial version.

Upvotes: 5

Related Questions