Thursday, December 23, 2010

Total line count for your Xcode project

The Apple developer ecosystem definitely takes some getting used to when you come from the Microsoft world. Visual Studio is millions of light years ahead of Xcode. That being said, most things are possible with a little work (and bash skills).

I don't claim to have any experience with *nix command line flavors. My command line experience is limited to several versions of MS-DOS back in the day. Luckily, that's where Google comes in handy.

After trying lots of different things, I landed on the following bash command. Open Terminal on your Mac and navigate to your project's root directory. (Handy trick: type cd with a space after it, then drag the root folder into Terminal, and it'll automatically paste in the entire path).
find . -name "*.[hm]" -print0 | xargs -0 wc -l
You'll get a list of every .h and .m file in your project (searching subdirectories recursively), with how many lines are in each file. Finally, you'll get a total line count for all files.

Note that this counts all lines, even blank lines and comments.

1 comment:

Bernard said...

Thanks, this was just what I needed. I appended "| sort" to the command string to sort the results by line count.