统计xcode代码行数

2017-07-27  本文已影响0人  蝼蚁撼树

如果要统计ios开发代码,包括头文件的,终端命令进入项目目录下,命令如下

find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" |xargs wc -l  

log 如下
列出每个文件的行数

      17 ./mytest/AppDelegate.h
      45 ./mytest/AppDelegate.m
      16 ./mytest/main.m
      29 ./mytest/MyObject.h
      30 ./mytest/MyObject.m
       4 ./mytest/mytest-Bridging-Header.h
      14 ./mytest/ViewController.h
     852 ./mytest/ViewController.m
      39 ./mytestTests/mytestTests.m
      40 ./mytestUITests/mytestUITests.m
    1086 total

你可以将你需要的文件行数直接相加,或者你可以直接使用下面的命令
列出代码行数总和 :

find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" |xargs grep -v "^$"|wc -l  

log 如下

950

当你的工程是swift 和OC 混编的情况下,你需要添加 -name "*.swift" 来统计swift 里面的行数

find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" -or  -name "*.swift" |xargs wc -l 

log 如下

bogon:mytest chengguangfa$ find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" -or  -name "*.swift" |xargs wc -l 
      17 ./mytest/AppDelegate.h
      45 ./mytest/AppDelegate.m
      16 ./mytest/main.m
      29 ./mytest/MyObject.h
      30 ./mytest/MyObject.m
       4 ./mytest/mytest-Bridging-Header.h
      21 ./mytest/testOK.swift
      14 ./mytest/ViewController.h
     852 ./mytest/ViewController.m
      39 ./mytestTests/mytestTests.m
      40 ./mytestUITests/mytestUITests.m
    1107 total

grep -v "^$"是去掉空行
注释也统计在代码量之内

上一篇 下一篇

猜你喜欢

热点阅读