Generate UML documentation from a binary framework (xcframework)

Generate UML documentation from a binary framework (xcframework)

Β·

2 min read

This blog post teaches you how to generate a UML class diagram for a given binary framework using two open-source tools, swiftplantuml and plantuml.

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.

For demonstration purposes, I will use the binary framework of Kingfisher, a Swift library for downloading and caching images from the web. You can download its 7.3.2 binary framework from here.

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.

Screen Shot 2022-08-11 at 2.38.54 PM.png

The file can be found under the framework's swiftmodule folder.

Screen Shot 2022-08-11 at 2.37.42 PM.png

Unzip the downloaded Kingfisher-7.3.2.zip archive.

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: kingfisher.puml ).

swiftplantuml Kingfisher-7.3.2/Kingfisher.xcframework/ios-arm64/Kingfisher.framework/Modules/Kingfisher.swiftmodule/arm64-apple-ios.swiftinterface --output consoleOnly > kingfisher.puml

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 plantuml locally.

Assuming you installed the plantuml.jar (and its prerequisites) in the same directory as the generated kingfisher.puml file then run the following command to generate the diagram.

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.

kingfisher

Here is a zoomed-in portion:

SVG zoomed in

SwiftPlantUML is available as open-source project on GitHub.

Did you find this article valuable?

Support Marco Eidinger by becoming a sponsor. Any amount is appreciated!