# Generate UML documentation from a binary framework (xcframework)

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](https://blog.eidinger.info/swiftplantuml-generate-class-diagrams-from-swift-with-swift).

%[https://blog.eidinger.info/swiftplantuml-generate-class-diagrams-from-swift-with-swift]

Or check out the related [Xcode source editor extension](https://github.com/MarcoEidinger/SwiftPlantUML-Xcode-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](https://github.com/onevcat/Kingfisher), a Swift library for downloading and caching images from the web. You can download its 7.3.2 binary framework from [here](https://github.com/onevcat/Kingfisher/releases/download/7.3.2/Kingfisher-7.3.2.zip).

The easiest way to install SwiftPlantUML is with Homebrew. You can find all installation options documented [here]((https://github.com/MarcoEidinger/SwiftPlantUML#installation)).

```bash
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](https://cdn.hashnode.com/res/hashnode/image/upload/v1660253952752/DCqXTbVC5.png align="left")

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

![Screen Shot 2022-08-11 at 2.37.42 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1660253881912/hjISjIilX.png align="left")

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` ).

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

![kingfisher.puml](https://cdn.hashnode.com/res/hashnode/image/upload/v1661104432950/sde5LVpyU.png align="left")

Optionally you can [configure](https://github.com/MarcoEidinger/SwiftPlantUML#configuration) SwiftPlantUML by adding a `.swiftplantuml.yml` file from the directory you'll run SwiftPlantUML from. For example, to hide extensions: 

```yml
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](https://github.com/MarcoEidinger/SwiftPlantUML#large-diagrams) it is better to generate the actual image with `plantuml` locally.

Assuming you [installed the `plantuml.jar`](https://plantuml.com/download) (and its [prerequisites](https://plantuml.com/starting)) in the same directory as the generated `kingfisher.puml` file then run the following command to generate the diagram.

```bash
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](https://user-images.githubusercontent.com/4176826/184239367-0e76a43d-4d32-47e1-8da3-9d1541f42e77.svg)](https://user-images.githubusercontent.com/4176826/184239367-0e76a43d-4d32-47e1-8da3-9d1541f42e77.svg)

Here is a zoomed-in portion:

![SVG zoomed in](https://cdn.hashnode.com/res/hashnode/image/upload/v1661106280488/UWGvT3lQQ.png align="left")

SwiftPlantUML is available as open-source project on GitHub.

%[https://github.com/MarcoEidinger/SwiftPlantUML]

