11

Is there a way to generate UML Class diagram for swift programming language? I found that the Mac A&D tool claims to be able to scan the swift code and create a class diagram. And there is a video to introduce it. https://wn.com/swift_code_to_class_diagram

Unfortunately, it is not free. I wonder if there is another free tool to generate class diagram automatically. Could you guys help me? Thanks in advance.

UML class diagrams for Xcode (swift programming)

Community
  • 1
  • 1
Leaf
  • 203
  • 1
  • 2
  • 13
  • Possible duplicate of [UML class diagrams for Xcode (swift programming)](http://stackoverflow.com/questions/29186136/uml-class-diagrams-for-xcode-swift-programming) – qwerty_so May 09 '17 at 08:02
  • @ThomasKilian, Do you mean that there is no free tool to generate class diagram automatically? – Leaf May 09 '17 at 08:05
  • Yes. If there were one, some kind soul would have answered differently. IIRC there is a non-free tool, but I can't recall its name. – qwerty_so May 09 '17 at 08:56
  • Perhaps it is MacA&D, I see it on YouTube. – Leaf May 09 '17 at 10:03
  • @ThomasKilian, would you mind telling me which free tool I can use to generate class diagram manually? – Leaf May 09 '17 at 10:10
  • I use Enterprise Architect. It's not free, but has an excellent price/performance ratio. The UI is a bit awkward, but you get used to it. Besides that there are tons of free (and expensive commercial) tools. Just google: there are also comparison pages. – qwerty_so May 09 '17 at 10:41

3 Answers3

11

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.

valosip
  • 3,167
  • 1
  • 14
  • 26
  • Seems to be not working with Swift Projects which has CocoaPods too. – arango_86 Aug 03 '17 at 12:52
  • Anyone make it in Swift Project? Please let me know. – arango_86 Aug 03 '17 at 12:53
  • @arango_86 I have used it. You need to put swift files to the swift-auto-diagram file manually. – Leaf Aug 07 '17 at 01:27
  • I was able to get it to work in a swift project which used cocoapods. But there were limitations. But it was a start – valosip Aug 08 '17 at 02:39
  • 4
    I'd say, it isn't worth it. Works only for mini-projects where you don't actually need the UML overview. As soon as you have a decent project you end up with a blob of overlapping rectangles that don't help in any way :-/ – qwerty_so Feb 08 '18 at 22:27
  • @Leaf wht exactly did you do "... put swift files to the swift-auto-diagram file manually ..."? – shallowThought Aug 21 '18 at 17:56
6

There are a number of free and open-source tools but those often require the user to manually install additional dependencies (e.g. NodeJS, Graphviz or Python). Some of the projects are no longer maintained and are limited when it comes to functionality. And none of these tools were written in Swift.

So I started to work on such utility myself.

Xcode extension: https://github.com/MarcoEidinger/SwiftPlantUML-Xcode-Extension

You are able to generate a class diagram from selected lines of code or from a whole file displayed in Xcode. The class diagram will then be opened in your browser. There you can modify the diagram with PlantUML notation

To generate a class diagram from multiple source files you can use the underlying CLI tool and Swift Package: https://github.com/MarcoEidinger/SwiftPlantUML

There is a size limitation to the visible diagram content (but you can delete content in the browser with PlantUML notation)

Marco Eidinger
  • 151
  • 2
  • 4
  • 1
    This one is awesome! Much better than current accepted answer and generates proper UML. Thank you Marco! – dokkaebi Jan 31 '22 at 23:26
-1

I found a tool that works quite well for swift projects: https://swiftalyzer.com It's free but time limited.

Chris
  • 21
  • 1