How to find out how many lines of code there are in an Xcode project?

Open up Terminal.app, go into your project's root directory, and run this command:

For Swift only:

find . \( -iname \*.swift \) -exec wc -l '{}' \+

For Obj-C only:

find . \( -iname \*.m -o -iname \*.mm -o -iname \*.h \) -exec wc -l '{}' \+

For Obj-C + Swift:

find . \( -iname \*.m -o -iname \*.mm -o -iname \*.h -o -iname \*.swift \) -exec wc -l '{}' \+

For Obj-C + Swift + C + C++:

find . \( -iname \*.m -o -iname \*.mm -o -iname \*.c -o -iname \*.cc -o -iname \*.h -o -iname \*.hh -o -iname \*.hpp -o -iname \*.cpp -o -iname \*.swift \) -exec wc -l '{}' \+

Terminal quick tips:
ls: list directory contents
cd: change directory
Press tab to autocomplete
Remember to put "\" backslash before spaces
I suggest going one folder down from the main project so you get rid of code count from the frameworks


Check out CLOC.

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.

(Legacy builds are archived on SourceForge.)


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
-------------------------------------------------------------------------------

I see this floating around and use it myself:

find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" -or -name "*.swift" ")" -print0 | xargs -0 wc -l