Swift Class Diagrams Remastered

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.

Screenshot 2019-03-24 at 00.44.20.png

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:

giphy.gif

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.

screen-shot-2016-10-09-at-11-05-37

You can also add it to your continuous integration build. Being a ruby scripts also makes it a nice fit in a fastlane setup.

Please check the GitHub repo for more details. Apart from that one, you can also check the Swift types navigator, if you need something different.

What do you think about this tool? Do you use it in your projects? Looking forward to any comments, suggestions and contributions.

Advertisements

About martinmitrevski

Software Engineer | Book Author | International Speaker. I love exploring and building things.

1 Response

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s