How to detect unused methods and #import in Objective-C

后端 未结 7 1004
天命终不由人
天命终不由人 2020-12-07 12:38

After working a long time on an iPhone app, I realized that my code is quite dirty, containing several #import and methods that are not called or useful at all.

I wo

7条回答
  •  醉酒成梦
    2020-12-07 13:18

    I recently wrote a script to find unused (or duplicate) #import statements: https://gist.github.com/Orangenhain/7691314

    The script takes an ObjC .m file and starts commenting out each #import line in turn and seeing if the project still compiles. You will have to change BUILD_DIR & BUILD_CMD.

    If you are using a find command to let the script run over multiple files, make sure to use a BUILD_CMD that actually uses all those files (or you will see a file with lots of unused import statements).

    I wrote this without knowing AppCode has a similar feature, however when I tested AppCode it was not as thorough as this script (but way faster [for a whole project]).

提交回复
热议问题