Count total number of lines in an Xcode project

Check out: CLOC

ClOC counts blank lines, comment lines, and physical lines of source code.

To use CLOC (Count Lines Of Code) for count number of lines in a project. Download the the CLOC .pl file and write following line in terminal:

perl ./DirectoryWhereClockFileIS/cloc-1.56.pl ./YourDirectoryWhereYourSourcesAre

It will show you results like:

enter image description here


If you don't want to pay $4.99 for a one time use, and you don't want to bother with HomeBrew. While it does count the empty lines between your code, you can do this:

  1. Open Terminal
  2. cd to your Xcode project
  3. Execute the following when inside your target project:

find . -name "*.swift" -print0 | xargs -0 wc -l

If you want to exclude pods:

find . -path ./Pods -prune -o -name "*.swift" -print0 ! -name "/Pods" | xargs -0 wc -l

If your project has objective c and swift:

find . -type d \( -path ./Pods -o -path ./Vendor \) -prune -o \( -iname \*.m -o -iname \*.mm -o -iname \*.h -o -iname \*.swift \) -print0 | xargs -0 wc -l

A lightweight solution if you're using Homebrew (and a fan of the terminal) is the command-line program 'Cloc' (count lines of code). It breaks down the output for languages used in your project and gives you other useful information.

Cloc

$ brew install cloc 
$ cd path/to/project/ 
$ cloc .

Tags:

Xcode

Rowcount