Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Tokuriku/f7d6ce5a68d2154c28b0 to your computer and use it in GitHub Desktop.

Select an option

Save Tokuriku/f7d6ce5a68d2154c28b0 to your computer and use it in GitHub Desktop.
Count lines of code in SWIFT Xcode project
1. Open Terminal
2. cd to your Xcode project
3. Execute the following when inside your target project:
find . -name "*.swift" -print0 | xargs -0 wc -l
@acidlynx

acidlynx commented Mar 2, 2016

Copy link
Copy Markdown
# brew install cloc
# cd path/to/project/
# cloc .

@nunogoncalves

nunogoncalves commented May 19, 2016

Copy link
Copy Markdown

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

(excluiding ./Pods from find)

@Exey

Exey commented Dec 23, 2016

Copy link
Copy Markdown

Mixed ObjC + Swift project:
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

@Rahulgupta-cdnsol

Copy link
Copy Markdown

How to exclude Comments and empty lines while counting the total number of lines, please suggest.

@cornr

cornr commented Jan 3, 2019

Copy link
Copy Markdown

For Jenkins Integration I suggest using cloc and SLOCCount Plugin.

Our cloc command looks something like this
cloc . --exclude-dir=Carthage,Frameworks,generated,.idea,output,derivedData,Fastlane --not-match-d=.*\.framework --by-file --xml --out=output/cloc.xml

@jakebromberg

Copy link
Copy Markdown

How would you exclude test files?

@dstuecken

dstuecken commented Oct 16, 2020

Copy link
Copy Markdown

You'd just add your test directories into the list of exclude-dirs. Here is an example to actually only count Swift code and Pods and Tests are excluded:

cloc . --exclude-dir=.\*Tests,Pods,Carthage,Frameworks,generated,.idea,output,DerivedData,Fastlane,.\*.xcodeproj,.\*.xcworkspace --include-ext=swift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment