如何查看Xcode项目中有多少行代码?

发布于 2024-08-16 23:55:28 字数 60 浏览 6 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

温馨耳语 2024-08-23 23:55:28

我看到这个漂浮在周围并自己使用它:

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

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
忘羡 2024-08-23 23:55:28

查看 CLOC

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

旧版本存档在 SourceForge 上。)

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

内心旳酸楚 2024-08-23 23:55:28

我一直在使用 CLOC 作为 Nathan Kinsinger 提到过,它相当容易使用。它是一个 PERL 脚本,您可以从项目目录添加并运行它。

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

perl cloc-1.56.pl ./YourDirectoryWhereYourSourcesAre

这是我从此类命令获得的输出示例:

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

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

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 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
-------------------------------------------------------------------------------
埖埖迣鎅 2024-08-23 23:55:28

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

仅适用于 Swift:

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

仅适用于 Obj-C:

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

适用于 Obj-C + Swift:

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

适用于 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 '{}' \+

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

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

For Swift only:

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

For Obj-C only:

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

For Obj-C + Swift:

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

For 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

紫瑟鸿黎 2024-08-23 23:55:28

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

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

如果您只需要某些文件类型,请尝试类似的操作

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

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
话少情深 2024-08-23 23:55:28
  1. 打开终端
  2. 导航到您的项目
  3. 在项目中执行以下命令:

    <前><代码>查找 . -path ./Pods -prune -o -name "*.swift" -print0 ! -名称“/Pods”| xargs -0 wc -l

    或者:

    <前><代码>查找 . -path ./Pods -prune -o -name "*[hm]" -print0 ! -名称“/Pods”| xargs -0 wc -l

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

  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)

梦情居士 2024-08-23 23:55:28

查看 Xcode Statistician,它完全可以满足您的需求。它还提供了其他有趣的统计数据,因此值得时不时地运行一下。

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

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

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.

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.

昔梦 2024-08-23 23:55:28

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

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

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

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.

硬不硬你别怂 2024-08-23 23:55:28

在 Mac 中实现 CLOC 库的步骤如下:

  1. 打开终端。
  2. 通过在终端中复制并粘贴以下命令(包括双引号)来安装Homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

如果询问,请输入系统密码。

您将看到如下所示的终端屏幕。

安装 Homebrew

系统会弹出这么多权限,允许所有权限

如果一切顺利,您将看到如下终端屏幕,

Homebrew 安装成功

  1. 现在是时候使用以下命令安装CLOC了。

brew install cloc

  1. 导航到项目目录并运行以下命令之一。

<代码>时钟。 --exclude-dir=Pods (排除 pod 文件)

cloc . (包括 pod 文件)

如果一切顺利,它将显示代码行数

“CLOC结果”

Steps to implement CLOC library in Mac as below:

  1. Open Terminal.
  2. Install Homebrew by copying and pasting the below command in the Terminal (including double quotes).

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Enter system password if asked.

You will see the terminal screen as below.

Installing Homebrew

System will popup so many permissions, allow all the permissions

If everything goes fine, you will see terminal screen as below,

Homebrew installation successful

  1. Now its time to install CLOC using below command.

brew install cloc

  1. Navigate to the project directory and run either of the following commands.

cloc . --exclude-dir=Pods (to exclude pod files)

cloc . (including pod files)

If everything goes fine, it will display the number of lines of code as below,

CLOC Result

眼角的笑意。 2024-08-23 23:55:28

Nozzi 的版本不适合我,但是这个:

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

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

find . -type f -print0 | xargs -0 cat | wc -l
行雁书 2024-08-23 23:55:28

快速&简单的方法:

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

.\n

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

A quick & easy way:

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

.\n

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

请叫√我孤独 2024-08-23 23:55:28

我不熟悉 xcode,但如果您需要的只是计算目录树中所有这些特定文件的行数,您可以使用以下命令:

find .... match of all those files ... -exec wc -l {} +

遵循 Joshua Nozzi 的回答,在 GNU find 中,此类文件的正则表达式如下:

find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" -or -name "*.swift" ")" -exec wc -l {} +

或者甚至

find -regex ".*\.\(m\|mm\|cpp\|swift\)$" -exec wc -l {} +

使用正则表达式来匹配以 < 结尾的所有文件代码>.m、.mm.cpp.swift。您可以在如何在文件查找中使用正则表达式中查看有关这些表达式的更多信息。

如果您使用Mac OS find,那么您需要稍微不同的方法,如 Motti 所解释的注释中的Shneor

find -E . -regex ".*\.([hmc]|mm|cp+|swift|pch)$" -exec wc -l {} +

两者都会提供以下形式的输出:

234 ./file1
456 ./file2
690 total

因此您可以像这样保留它,或者只是通过管道传输到tail -1(即find .. . | tail -1) 这样你就可以得到最后一行的总数。

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.

甜妞爱困 2024-08-23 23:55:28

您可以通过 MacPorts 安装 SLOCCount。或者,更粗略地说,您可以使用 wc -l。

You can install SLOCCount through MacPorts. Or, more crudely, you can use wc -l.

怀念你的温柔 2024-08-23 23:55:28

line-counter 是一个不错的选择。它比 CLOC 更轻,并且比其他命令更强大且更易于使用。

快速概述

这是获取该工具的方式

$ pip install line-counter

使用 line 命令获取当前目录下的文件数和行数(递归)

$ line
Search in /Users/Morgan/Documents/Example/
file count: 4
line count: 839

如果您想要更多详细信息,只需使用 line -d.

$ line -d
Search in /Users/Morgan/Documents/Example/
Dir A/file C.c                                             72
Dir A/file D.py                                           268
file A.py                                                 467
file B.c                                                   32
file count: 4
line count: 839

这个工具最好的部分是,您可以向其中添加 .gitignore 之类的配置文件。您可以设置规则来选择或忽略要计数的文件类型,就像在“.gitignore”中所做的那样。是的,这个工具只是为了让我更容易知道我有多少行而发明的。

更多描述和用法在这里:https://github.com/MorganZhang100/line-counter

我是这个简单工具的作者。希望它可以帮助别人。

line-counter is a good alternative. It's lighter than CLOC and much more powerful and easier to use than other commands.

A quick overview

This is how you get the tool

$ pip install line-counter

Use line command to get the file count and line count under current directory (recursively)

$ line
Search in /Users/Morgan/Documents/Example/
file count: 4
line count: 839

If you want more detail, just use line -d.

$ line -d
Search in /Users/Morgan/Documents/Example/
Dir A/file C.c                                             72
Dir A/file D.py                                           268
file A.py                                                 467
file B.c                                                   32
file count: 4
line count: 839

And the best part of this tool is, you can add .gitignore like configure file to it. You can set up rules to select or ignore what kind of files to count just like what you do in '.gitignore'. Yes, this tool is just invented to make knowing how many lines I have easier.

More description and usage is here: https://github.com/MorganZhang100/line-counter

I'm the author of this simple tool. Hope it can help somebody.

π浅易 2024-08-23 23:55:28

简单方法 - 100% 经过测试

当我在处理一个 swift 项目时,有时我会很想知道我实际编写了多少行代码。看看会很有趣。然而,我不会只是坐在那里数每一行,我们毕竟是程序员,我们可以做得更好!

使用终端
打开终端并导航到您的项目:

cd path/to/your/project/

接下来,输入以下代码行之一以获取项目中的总行数。它的工作原理是读取目录中的所有 swift 文件(对不起 objc 用户!)并计算行数。

不包括 Pod

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

Pod


find . -name '*.swift' -print0 | xargs -0 wc -l

包括使用 Cloc 的
如果您的 Mac 上有自制程序,则有一种更简单的方法来显示行数。使用终端导航到您的项目:

cd path/to/your/project/

接下来,安装 Cloc

brew install cloc

最后,输入以下命令之一

不包括 Pods

cloc . --exclude-dir=Pods

包括 Pods

cloc .

结果:

在此处输入图像描述

Easy way - 100% working Tested

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 .

Results:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文