Detecting unused iOS methods

A very simple question and hopefully not duplicated :).

The situation is as follows:

Project been developing for more than a year and many developers.
From time to time I come across unused methods (which are defined in .h and .m), it is obvious that I do not receive any warnings .

This is not critical, but I would like the project to be cleared of all unnecessary employees. Of course, I can search for all the methods and determine which are not used in the project, but I wonder if there is a more elegant way ?!

thanks

+6
source share
3 answers

A quick view when viewing the source code is the menu "View"> "Standard Editor"> "Show Related Items" (key combination: ^ 1). Place the cursor in the body of the method, and then view the callers.

enter image description here

+8
source

AppCode ( http://www.jetbrains.com/objc ) can tell you that the method or import is not used. It works in real time, but you can also check the whole project (menu code> check code)

enter image description here

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

+4
source

May I suggest adding NSLOG to these methods. For example, if you have a View Controller named Home, you can go to 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 review the readings as you progress with this view controller. The magazine should say something that best describes the method in question. Step 2 - take methods that, in your opinion, are not displayed on the output and do not comment on them. This can be done by highlighting the method and then pressing Command + '/' on the keyboard. This places a '//' in front of each highlighted line, commenting on it. Recheck the view controller and, if there are still no errors, you can remove this method. This is a free way to do this, but it will take some time.

-3
source

Source: https://habr.com/ru/post/972171/


All Articles