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

前端 未结 15 1539
闹比i
闹比i 2020-11-30 16:32

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

相关标签:
15条回答
  • 2020-11-30 16:56

    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.

    0 讨论(0)
  • 2020-11-30 16:58

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

    0 讨论(0)
  • 2020-11-30 16:59
    1. open terminal
    2. navigate to your project
    3. 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)

    0 讨论(0)
提交回复
热议问题