xcode 如何找出Xcode项目中有多少行代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2003534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:14:08  来源:igfitidea点击:

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

xcodecode-metrics

提问by Dave Gallagher

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

有没有办法确定一个 Xcode 项目包含多少行代码?我保证不会将此类信息用于管理衡量或员工基准测试目的。;)

采纳答案by Nathan Kinsinger

Check out CLOC.

查看CLOC

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.

cloc 计算许多编程语言中源代码的空白行、注释行和物理行数。

(Legacy builds are archived on SourceForge.)

旧版本存档在 SourceForge 上。)

回答by Joshua Nozzi

I see this floating around and use it myself:

我看到这个浮动并自己使用它:

find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" -or -name "*.swift" ")" -print0 | xargs -0 wc -l

回答by tiguero

I have been using CLOCas mentioned by Nathan Kinsingerand it is fairly easy to use. It is a PERL script that you can add and run from your project directory.

正如提到的Nathan Kinsinger,我一直在使用CLOC,它非常易于使用。它是一个 PERL 脚本,您可以在项目目录中添加和运行它。

PERL is already part of Mac OS and you can invoke the script this way to find out your number of lines you have written:

PERL 已经是 Mac OS 的一部分,您可以通过这种方式调用脚本来找出您编写的行数:

perl cloc-1.56.pl ./YourDirectoryWhereYourSourcesAre

This is an example of output i got from such command:

这是我从这样的命令得到的输出示例:

   176 text files.
   176 unique files.                                          
     4 files ignored.

http://cloc.sourceforge.net v 1.56  T=2.0 s (86.0 files/s, 10838.0 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Objective C                     80           3848           1876          11844
C/C++ Header                    92            980           1716           1412
-------------------------------------------------------------------------------
SUM:                           172           4828           3592          13256
-------------------------------------------------------------------------------

回答by Esqarrouth

Open up Terminal.app, go into your project's root directory, and run this command:

打开 Terminal.app,进入你项目的根目录,然后运行以下命令:

For Swift only:

仅适用于 Swift:

find . \( -iname \*.swift \) -exec wc -l '{}' \+

For Obj-C only:

仅适用于 Obj-C:

find . \( -iname \*.m -o -iname \*.mm -o -iname \*.h \) -exec wc -l '{}' \+

For Obj-C + Swift:

对于 Obj-C + Swift:

find . \( -iname \*.m -o -iname \*.mm -o -iname \*.h -o -iname \*.swift \) -exec wc -l '{}' \+

For Obj-C + Swift + C + C++:

对于 Obj-C + Swift + C + C++:

find . \( -iname \*.m -o -iname \*.mm -o -iname \*.c -o -iname \*.cc -o -iname \*.h -o -iname \*.hh -o -iname \*.hpp -o -iname \*.cpp -o -iname \*.swift \) -exec wc -l '{}' \+

Terminal quick tips:
ls: list directory contents
cd: change directory
Press tab to autocomplete
Remember to put "\" backslash before spaces
I suggest going one folder down from the main project so you get rid of code count from the frameworks

终端快速提示:
ls:列出目录内容
cd:更改目录
按 T​​ab 键自动完成
记住在空格前放置“\”反斜杠
我建议从主项目向下移动一个文件夹,这样您就可以摆脱框架中的代码计数

回答by Andrew McGregor

In terminal, change into the project directory and run:

在终端中,切换到项目目录并运行:

find . -type f -print0 | xargs -0 cat | wc -l

If you want only certain file types, try something like

如果您只想要某些文件类型,请尝试类似

find . -type f -name \*.[ch]* -print0 | xargs -0 cat | wc -l

回答by Matthew Frederick

Check out Xcode Statistician, it does exactly what you want. It also provides other interesting statistics so is worth a run for fun now and then.

查看 Xcode Statistician,它完全符合您的要求。它还提供了其他有趣的统计数据,因此值得时不时地跑一趟。

Note that it will not look inside real folders, though it will look in groups. Odds are you aren't using real folders so it'll work great. If you are using folders then you just have to do the count in each folder and add them together.

请注意,它不会查看真正的文件夹,但会按组查看。很可能你没有使用真正的文件夹,所以它会很好用。如果您正在使用文件夹,那么您只需在每个文件夹中进行计数并将它们加在一起。

Note:As of June, 2012, it seems this does not work properly with the latest versions of Xcode.

注意:截至 2012 年 6 月,这似乎在最新版本的 Xcode 中无法正常工作。

回答by Shan Shafiq

  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
    
  1. 打开终端
  2. 导航到您的项目
  3. 在您的项目中执行以下命令:

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

    或者:

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

(*Excluding pod files count from total count)

(*从总数中排除 pod 文件数)

回答by RileyE

If you go to your project's directory in terminal and enter:

如果您在终端中转到项目目录并输入:

find . "(" -name "*.h" -or -name "*.m" -or -name "*.mm" -or -name "*.hpp" -or -name "*.cpp"  -or  -name "*.c" -or -name "*.cc" -or -name "*.swift" ")" -print0 | xargs -0 wc -l

That will give you a project breakdown, as well as the line total for each file and the project as a whole.

这将为您提供项目细分,以及每个文件和整个项目的总行数。

回答by Pascalius

Nozzi's version doesn't work for me, but this one:

Nozzi 的版本对我不起作用,但这个版本:

find . -type f -print0 | xargs -0 cat | wc -l

回答by Patrick Pijnappel

A quick & easy way:

一种快速简便的方法:

Use a regex search (Find Navigator, choose Find > Regular Expression).

使用正则表达式搜索(“查找导航器”,选择“查找”>“正则表达式”)。

.\n

.\n

Works conveniently with Xcode search scopes and you can easily customize it to whatever type of line you'd like to count ;).

使用 Xcode 搜索范围方便地工作,您可以轻松地将其自定义为您想要计算的任何类型的行;)。