计算 Xcode 项目中的总行数
Count total number of lines in an Xcode project
如何计算Xcode项目中的总行数?我可以看到单个文件中的行数,但我需要项目中所有行的总和。
App Store 上有一个名为 Xcode Statistics 的应用程序。 (或类似的东西)。它做你想做的事。
不过要提醒一句。项目中的行数与该项目的质量或复杂性几乎没有关系。
如果您使用 Homebrew(并且是终端的粉丝),一个轻量级的解决方案是命令行程序 'Cloc'(计算代码行数)。它会分解项目中使用的语言的输出,并为您提供其他有用的信息。
$ brew install cloc
$ cd path/to/project/
$ cloc .
查看:CLOC
ClOC counts blank lines, comment lines, and physical lines of source
code.
使用 CLOC(计算代码行数)来计算项目中的行数。下载 CLOC .pl 文件并在终端中写入以下行:
perl ./DirectoryWhereClockFileIS/cloc-1.56.pl ./YourDirectoryWhereYourSourcesAre
它会显示如下结果:
如果您不想为一次性使用支付 4.99 美元,并且不想为 HomeBrew 而烦恼。虽然它会计算代码之间的空行,但您可以这样做:
- 打开终端
- cd 到您的 Xcode 项目
- 在目标项目中执行以下操作:
find . -name "*.swift" -print0 | xargs -0 wc -l
如果要排除pods:
find . -path ./Pods -prune -o -name "*.swift" -print0 ! -name "/Pods" | xargs -0 wc -l
如果您的项目有 objective c 和 swift:
find . -type d \( -path ./Pods -o -path ./Vendor \) -prune -o \( -iname \*.m -o -iname \*.mm -o -iname \*.h -o -iname \*.swift \) -print0 | xargs -0 wc -l
如何计算Xcode项目中的总行数?我可以看到单个文件中的行数,但我需要项目中所有行的总和。
App Store 上有一个名为 Xcode Statistics 的应用程序。 (或类似的东西)。它做你想做的事。
不过要提醒一句。项目中的行数与该项目的质量或复杂性几乎没有关系。
如果您使用 Homebrew(并且是终端的粉丝),一个轻量级的解决方案是命令行程序 'Cloc'(计算代码行数)。它会分解项目中使用的语言的输出,并为您提供其他有用的信息。
$ brew install cloc
$ cd path/to/project/
$ cloc .
查看:CLOC
ClOC counts blank lines, comment lines, and physical lines of source code.
使用 CLOC(计算代码行数)来计算项目中的行数。下载 CLOC .pl 文件并在终端中写入以下行:
perl ./DirectoryWhereClockFileIS/cloc-1.56.pl ./YourDirectoryWhereYourSourcesAre
它会显示如下结果:
如果您不想为一次性使用支付 4.99 美元,并且不想为 HomeBrew 而烦恼。虽然它会计算代码之间的空行,但您可以这样做:
- 打开终端
- cd 到您的 Xcode 项目
- 在目标项目中执行以下操作:
find . -name "*.swift" -print0 | xargs -0 wc -l
如果要排除pods:
find . -path ./Pods -prune -o -name "*.swift" -print0 ! -name "/Pods" | xargs -0 wc -l
如果您的项目有 objective c 和 swift:
find . -type d \( -path ./Pods -o -path ./Vendor \) -prune -o \( -iname \*.m -o -iname \*.mm -o -iname \*.h -o -iname \*.swift \) -print0 | xargs -0 wc -l