by matsoftware

matsoftware / swift-code-metrics

Code metric analyzer for Swift projects.

225 Stars 3 Forks Last release: 3 months ago (1.4.1) MIT License 213 Commits 16 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

FOSSA Status License Build Status codecov Codacy Badge PyPI


Code metrics analyzer for Swift projects.

| Example code distribution Example deviation main sequence | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Example internal distribution |


The goal of this software is to provide an insight of the architectural state of a software written in

that consists in several modules. Inspired by the book of Robert C. Martin, Clean Architecture, the software will scan the project to identify the different components in order to assess several common code metrics in the software industry:
  • the overall number of concrete classes and interfaces
  • the instability and abstractness of the framework
  • the distance from the main sequence
  • LOC (Lines Of Code)
  • NOC (Numbers Of Comments)
  • POC (Percentage Of Comments)
  • NOM (Number of Methods)
  • Number of concretes (Number of classes and structs)
  • NOT (Number Of Tests)
  • NOI (Number Of Imports)
  • Frameworks dependency graph (number of internal and external dependencies)


This is a Python 3 script that depends on matplotlib, adjustText, pyfunctional and pygraphviz.

This latest package depends on the Graphviz binary that must be installed.


The package is available on

pip3 install swift-code-metrics

The syntax is:

swift-code-metrics --source  --artifacts  --exclude  --tests-paths  --generate-graphs
  • --source
    is the path to the folder that contains the main Xcode project or Workspace
  • --artifacts
    path to the folder that will contain the generated
  • --excluded
    (optional) space separated list of path substrings to exclude from analysis (e.g.
    will ignore all files/folders that contain
  • --tests-paths
    Test Tests
    ) space separated list of path substrings matching test classes
  • --generate-graphs
    (optional) if passed, it will generate the graphs related to the analysis and save them in the artifacts folder


Please follow the guide with a practical example to get started.

Current limitations

  • This tool is designed for medium/large codebases composed by different frameworks. The script will scan the directory and it will identify the frameworks by the name of the 'root' folder, so it's strictly dependent on the file hierarchy (unless a project path override file is specified)

  • Libraries built with

    are not supported.
  • The framework name is inferred using the directory structure. If the file is in the root dir, the

    will be used. No inspection of the xcodeproj will be made.
  • The list of methods currently doesn't support computed vars

  • Inline comments in code (such as

    struct Data: {} //dummy data
    ) are currently not supported
  • Only

    test frameworks are currently supported


  • Code improvements
  • Other (open to suggestions)


Mattia Campolese

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.