This blog post teaches you how to generate a UML class diagram for a given binary framework using two open-source tools,
PlantUML allows users to create diagrams from a plain text language. SwiftPlantUML converts Swift code into this plain text language. If you are unfamiliar with SwiftPlantUML please read my introductory blog post.
Or check out the related Xcode source editor extension if you instead want to generate a class diagram from a single Swift source file.
The easiest way to install SwiftPlantUML is with Homebrew. You can find all installation options documented here.
brew install swiftplantuml
Once you installed SwiftPlantUML the trick is to specify the
.swiftinterface file explicitly 💡
In case you are unfamiliar with this kind of file: A
.swiftinterface file is autogenerated when a binary framework is created. The file describes the public interface of a binary framework along with linker flags, used toolchain and other info.
The file can be found under the framework's
Unzip the downloaded
The following command will use
swifplantuml to parse the
.swiftmodule file, create a textual, PlantUML-conforming representation and save the content into a file (here:
swiftplantuml Kingfisher-7.3.2/Kingfisher.xcframework/ios-arm64/Kingfisher.framework/Modules/Kingfisher.swiftmodule/arm64-apple-ios.swiftinterface --output consoleOnly > kingfisher.puml
Optionally you can configure SwiftPlantUML by adding a
.swiftplantuml.yml file from the directory you'll run SwiftPlantUML from. For example, to hide extensions:
elements: showExtensions: false
I am using the option
--output consoleOnly as a binary file normally contains a lot of structs, classes, protocols and enums which then results in a very large diagram. As described in Large Diagrams it is better to generate the actual image with
java -DPLANTUML_LIMIT_SIZE=8192 -jar plantuml.jar -nometadata -svg kingfisher.puml
I recommend saving the diagram as a Scalable Vector Graphics (SVG) file because the diagram's content might not be completely rendered in a Portable Network Graphic (PNG) file.
Here is a zoomed-in portion:
SwiftPlantUML is available as open-source project on GitHub.