A picture is worth a thousand words. An architecture drawing – countless explanations. Sometimes, visualising concepts and implementations can bring much better understanding of the bigger picture. We can learn much about the design of a system, the dependencies between the components, how they communicate between them, by looking at different types of diagrams. Such drawings are very useful when onboarding new members to the team.
Back in October 2016, a tool for visualising Swift code (the first of its kind) was introduced by Jovan Jovanovski and Zdravko Nikolovski. After a solid adoption of the community with over 220 stars, questions, opened issues and many blog post visits, the tool is now remastered and better than ever.
The performance has improved a lot. The diagram is generated faster than the initial implementation. There are many bug fixes. Also, the UI of the generated diagrams is much nicer (with new colors and look and feel), giving an even better overview of the Swift code.
Let’s revisit the steps to use the tool:
1. Clone the git repo:
git clone https://github.com/yoshimkd/swift-auto-diagram
2. Run the generateEntityDiagram.rb script with the path of your project as an argument (you can also select specific sub-folder in your project):
ruby generateEntityDiagram.rb ~/workspace/my-swift-project
3. Open the generated html and enjoy the diagrams of your Swift types.
If we perform these steps on the Girders for Swift project, we get the following diagram:
There are different colors for the different types – blue for classes and structs, purple for protocols, green for extensions, yellow for enums.
Since this is a ruby script, you can add it as a run script phase to your project’s Build Phases. The script will update the html of the class diagram any time you build the project, therefore always providing an up-to date overview of the state of your project.
You can also add it to your continuous integration build. Being a ruby scripts also makes it a nice fit in a fastlane setup.
What do you think about this tool? Do you use it in your projects? Looking forward to any comments, suggestions and contributions.