How To Check The Total Lines Of Code In Your Xcode Project

When I’m working on a swift project, I sometime’s get the urge to know how many lines of code I have actually written. It would be interesting to see. However, I’m not just going to sit there counting every single line, we’re programmers after all, we can do better!

Using Terminal

Open up terminal and navigate to your project:

cd path/to/your/project/

Next, type in one of the following lines of code to get the total number of lines in your project. It works by reading all the swift files (sorry objc users!) in your directory and counting up the lines.

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

Using Cloc

If you have homebrew on your mac, there is a much easier way to show the number of lines. Navigate to your project using terminal:

cd path/to/your/project/

Next, install Cloc

brew install cloc

Finally, type in one of the following commands

Not Including Pods
cloc . --exclude-dir=Pods
Including Pods
cloc .

Done! How easy was that? Now you can brag to your friends that your project has 3 more lines of code than theirs.

Thanks to AppMakers.dev for the original article: https://appmakers.dev/how-to-count-lines-in-xcode-project/