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 purp
I am not familiar with xcode, but if all you need is to count the number of lines from all those specific files within a directory tree, you may use the following command:
find .... match of all those files ... -exec wc -l {} +
Following Joshua Nozzi's answer, in GNU find the regular expression for such files would be like:
find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" -or -name "*.swift" ")" -exec wc -l {} +
or even
find -regex ".*\.\(m\|mm\|cpp\|swift\)$" -exec wc -l {} +
this uses a regular expression to match all files ending in either .m
, .mm
, .cpp
or .swift
. You can see more information about those expressions in How to use regex in file find.
If you are working with Mac OS find, then you need a slightly different approach, as explained by Motti Shneor in comments:
find -E . -regex ".*\.([hmc]|mm|cp+|swift|pch)$" -exec wc -l {} +
Both will provide an output on the form of:
234 ./file1
456 ./file2
690 total
So you can either keep it like this or just pipe to tail -1
(that is, find ... | tail -1
) so that you just get the last line being the total.
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.)
execute following command inside your project:
find . -path ./Pods -prune -o -name "*.swift" -print0 ! -name "/Pods" | xargs -0 wc -l
Or:
find . -path ./Pods -prune -o -name "*[hm]" -print0 ! -name "/Pods" | xargs -0 wc -l
(*Excluding pod files count from total count)