SoFunction
Updated on 2025-04-08

Command to count the total number of code lines in iOS (convenient and simple)

Sometimes we want to count the total number of lines of code in our project to get some sense of accomplishment or use it as another graph. Here we will introduce some how to easily count the number of lines of code. It is very simple, and the method is as follows:

1. Open the terminal;

2. Arrive our project files through the cd command. Here we note that if we want to avoid counting the number of codes in the third-party library referenced, we must further enter the code files we wrote ourselves, which are generally a file with the same name as the project file;

3. Statistics the number of lines of code:

If you want to list the number of lines for each file, enter the command:

find.-name"*.m"-or-name"*.h"-or-name"*.xib"-or-name"*.c"|xargswc-l

If you want to list the total number of lines of code directly, enter the command:

find.-name"*.m"-or-name"*.h"-or-name"*.xib"-or-name"*.c"|xargsgrep-v"^$"|wc-l

This way you can directly obtain the quantity, and it is very fast, isn't it very convenient?

This statistical process will remove blank lines, but comments will be counted.

Summarize

The above is the command (convenient and simple) for counting the total number of iOS code lines introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!