Take the 2-minute tour ×

Is there a way to determine how many lines of code an Xcode project contains? I promise not to use such information for managerial measurement or employee benchmarking purposes. ;)

share|improve this question
If you want lines, then you can use this answer: stackoverflow.com/questions/5901758/… But it includes spaces –  Rocotilos Feb 27 at 9:38

6 Answers 6

up vote 40 down vote accepted

Check out CLOC.


share|improve this answer
CLOC is available via Homebrew. The ease of use in the command line was refreshing. –  avelis Apr 24 '13 at 0:26
I love the pun in the name there -- yes you can tell how productive you've been by checking out your CLOC. –  bobobobo May 15 '13 at 2:41
Use above link to download './cloc-1.56.pl' perm version of cloc tool. Make sure that you enable execution permission on cloc-1.56.pl file using 'chmod u+x cloc-1.56.pl' command. If your source code is located in directory 'project_code' You just need to run following command. –  JZ. Sep 26 at 3:41

In terminal, change into the project directory and run:

find . -type f -print0 | xargs -0 cat | wc -l

If you want only certain file types, try something like

find . -type f -name \*.[ch]* -print0 | xargs -0 cat | wc -l
share|improve this answer
Nice, but includes comments and blank lines and thus is not exactly what was asked for. A LOC measure should be as independent of code formatting style as possible and thus a bunch of blank lines or comments between to logical parts in a file shouldn't count towards the sum. –  bassim Aug 28 at 12:41

I have been using CLOC as mentioned by Nathan Kinsinger and it is fairly easy to use. It is a PERL script that you can add and run from your project directory.

PERL is already part of Mac OS and you can invoke the script this way to find out your number of lines you have written:

perl cloc-1.56.pl ./YourDirectoryWhereYourSourcesAre

This is an example of output i got from such command:

   176 text files.
   176 unique files.                                          
     4 files ignored.

http://cloc.sourceforge.net v 1.56  T=2.0 s (86.0 files/s, 10838.0 lines/s)
Language                     files          blank        comment           code
Objective C                     80           3848           1876          11844
C/C++ Header                    92            980           1716           1412
SUM:                           172           4828           3592          13256
share|improve this answer

If you go to your project's directory in terminal and enter:

find . "(" -name "*.h" -or -name "*.m" -or -name "*.mm" -or -name "*.hpp" -or -name "*.cpp"  -or  -name "*.c" -or -name "*.cc" ")" -print0 | xargs -0 wc -l

That will give you a project breakdown, as well as the line total for each file and the project as a whole.

share|improve this answer

You can install SLOCCount through MacPorts. Or, more crudely, you can use wc -l.

share|improve this answer
CLOC is based on SCLOCount so i guess it is still a better approach to use CLOC –  tiguero Oct 22 '12 at 22:31
"Total Estimated Cost to Develop = $ 1,934,715". This made my day! –  Valeriy Van Jul 25 at 19:58

A quick & easy way:

Use a regex search (Find Navigator, choose Find > Regular Expression).


Works conveniently with Xcode search scopes and you can easily customize it to whatever type of line you'd like to count ;).

share|improve this answer

Your Answer


