Using SourceKitten and PlantUML to generate UML class diagrams from swift source code.
sh plantuml.sh demo.swift
If you want to run on multiple files at the moment, you can do some command line kung fu like below
ls -d "/directory/full/of/swift/files/"* | xargs -L 1 sh plantuml.sh | pbcopy
or if you list of files with fullpath
cat ~/Downloads/listOfFilesWithFullPath.txt | xargs -L 1 | xargs -L 1 sh plantuml.sh | pbcopy
once it copy everything to your clipboard (MacOS) you can paste it in your favorite text editor replace multiple @startuml
and @enduml
block and have just one startuml at top and enduml at the bottom
sh plantuml.sh demo.swift
will produce this diagram Full Image
Generates the below content, which you can copy and paste it in PlantText
@startuml
' STYLE START
hide empty members
skinparam shadowing false
' STYLE END
class "FullyNamed" as FullyNamed << (P,GoldenRod) protocol >> {
}
class "Togglable" as Togglable << (P,GoldenRod) protocol >> {
~toggle()
}
class "Named" as Named << (P,GoldenRod) protocol >> {
}
class "Aged" as Aged << (P,GoldenRod) protocol >> {
}
class "CounterDataSource" as CounterDataSource << (P,GoldenRod) protocol >> {
~increment(forCount:): Int
}
class "Vehicle" as Vehicle {
~makeNoise()
}
class "Bicycle" as Bicycle {
}
class "Tandem" as Tandem {
}
class "Train" as Train {
~makeNoise()
}
class "Car" as Car {
}
class "AutomaticCar" as AutomaticCar {
}
class "Starship" as Starship {
~init(name:prefix:)
}
class "Counter" as Counter {
~increment()
}
class "ThreeSource" as ThreeSource {
}
class "TowardsZeroSource" as TowardsZeroSource {
~increment(forCount:): Int
}
class "AnotherPublicClass" as AnotherPublicClass {
+somePublicProperty
-somePrivateMethod()
}
class "AnotherInternalClass" as AnotherInternalClass {
-somePrivateMethod()
}
class "AnotherFilePrivateClass" as AnotherFilePrivateClass {
~someFilePrivateMethod()
-somePrivateMethod()
}
class "AnotherPrivateClass" as AnotherPrivateClass {
~somePrivateMethod()
}
class "Rect" as Rect << (S, SkyBlue) struct >> {
}
class "Person" as Person << (S, SkyBlue) struct >> {
}
class "Person2" as Person2 << (S, SkyBlue) struct >> {
}
class "IntStack" as IntStack << (S, SkyBlue) struct >> {
~push(_:)
~pop(): Int
}
class "Stack" as Stack << (S, SkyBlue) struct >> {
~push(_:)
~pop(): Element
}
class "OnOffSwitch" as OnOffSwitch << (E,LightSteelBlue) enum >> {
~toggle()
}
class "Double" as Double25 << (E,orchid) extension >> {
}
class "Rect" as Rect26 << (E,orchid) extension >> {
-init(center:size:)
}
class "Stack" as Stack27 << (E,orchid) extension >> {
}
Bicycle -u-|> Vehicle : inherits
Tandem -u-|> Bicycle : inherits
Train -u-|> Vehicle : inherits
Car -u-|> Vehicle : inherits
AutomaticCar -u-|> Car : inherits
Starship .u.|> FullyNamed : confirms to
ThreeSource -u-|> NSObject
ThreeSource .u.|> CounterDataSource : confirms to
TowardsZeroSource -u-|> NSObject
TowardsZeroSource .u.|> CounterDataSource : confirms to
Person .u.|> FullyNamed : confirms to
Person2 .u.|> Named : confirms to
Person2 .u.|> Aged : confirms to
OnOffSwitch .u.|> Togglable : confirms to
Double <.. Double25 : ext
Rect <.. Rect26 : ext
Stack <.. Stack27 : ext
@enduml
-
Generates output for PlantText*