Swift Code to Class Diagram

Swift code to class diagram

I recently found a free tool, that gets you a decent start on this.

Take a look at this tutorial https://martinmitrevski.com/2016/10/12/swift-class-diagrams-and-more/

and here is the github repo https://github.com/yoshimkd/swift-auto-diagram.

I found its best if you open the diagram.html in chrome vs firefox. And if you see the little circles, just let it run until its finished. It takes a few minutes on my project.

UML class diagrams for Xcode (Swift programming)

The answer unfortunately is: you can't do it. At least not automatically. Swift as compiler itself has enough flaws left. Leave alone some tool will be able to swallow any Swift code. Your only alternative is the good old manual way.

I know that Enterprise Architect has a possibility to define a language syntax based on BNF. But Swift is (again unfortunately) not context free. (In fact it's so context sensitive that it often swallows its own rear.) So that won't work either.

P.S.: Now that Swift is open source someone might take the opportunity to tap the compiler's output for the class interfaces. I guess that should not be too difficult, but it's a lot of work still.

How can I automatically generate UML diagrams from Objective-C code?

Have a look at doxygen. Which seem to have support for Objective-C. It might not give you an UML diagram but it is able to show references etc in graphs and with added comments you can give more information for the formatted output.

See here for an example in Objective-C, the clang project (oups, clang is actually written in C++ and works on Objective-C code) But I found this blog post about using doxygen for Objective-C code

Swift Access Control When to Use Which Preceding Symbols For a Class Diagram

As you have noticed, Java is really different from Swift. :)

Swift has the following access modifiers, from the most accessible to the least:

  • open
  • public
  • internal
  • fileprivate
  • private

They all behave quite differently from their Java counterparts (if any). So my suggestion is to not try to find equivalents of them in Java. Forget everything you know about Java and try to come up with symbols that are specific to Swift. For example, I came up with:

++    open
+ public
~ internal
-~ fileprivate
- private

You can also argue that it is not quite useful to differentiate fileprivate from private because in a class diagram, you can't see which classes belong to which files. You can use - for both of them.


I found this project that generates a class diagram of your swift code. From the looks of it, it doesn't seem to generate anything that indicates the access modifier.

Is there a way to create UML diagram from ios project automatically?

If you have omnigraffle https://www.omnigroup.com/omnigraffle you can drag and drop the project folds to the icon of the program and then a umlaut like diagrams is generated

Automatically create class diagram from ActionScript code?

I just searched google and quickly found, http://seantheflexguy.com/blog/2007/11/20/actionscript-30-uml-and-code-generation-tools/.

Perhaps more promising is: http://www.gskinner.com/gmodeler/ Goes from Diagram to stubs, it that is what you are looking for.

I know the UML tools space pretty well, but have not needed to use actionscript and UML. Good Luck.



Related Topics



Leave a reply



Submit