Awesome
<p align="center"> <img src="./SwiftPlantUMLApp/Assets.xcassets/AppIcon.appiconset/128.png" width="100" max-width="50%" alt="SwiftPlantUML" /> </p>SwiftPlantUML.app
Generate and view a class diagram for Swift code in Xcode or from the Finder.
Use the hosting macOS application to configure the diagram visualization.
The Source Editor Extension (as well as the Action extension) makes use of SwiftPlantUML
Swift package.
To generate a large diagram from a project with Swift files across folders then I recommend using SwiftPlantUML
as a command-line tool.
Features
Xcode
- 📊 Create class diagram from Swift file
- 🔦 Create class diagram from selected Swift code
Finder
- 📊 Create class diagram from selected Swift file(s)
https://user-images.githubusercontent.com/4176826/218329052-b03ec650-d845-46a2-a31b-6d3817add52a.mp4
Example
Install
Homebrew
brew install swiftplantumlapp
<img width="565" alt="Installation through Homebrew" src="https://user-images.githubusercontent.com/4176826/150718736-f94d9e81-076e-4254-906f-be68518d0450.png">
Alternative
- Download latest SwiftPlantUML package from the Releases.
- Copy SwiftPlantUML to your Applications folder.
Enable Extension
-
Launch SwiftPlantUML.
<img width="712" alt="SwiftPlantUML user interface" src="https://user-images.githubusercontent.com/4176826/150644606-a4eb8681-d9dc-46d9-87b1-4522ed88668e.png"> -
To use in Xcode: enable extension in <kbd>System Preferences</kbd> > <kbd>Extensions</kbd> > <kbd>Xcode Source Editor</kbd> > select <kbd>SwiftPlantUML</kbd>
-
To use in Finder: enable extension in <kbd>System Preferences</kbd> > <kbd>Extensions</kbd> > <kbd>Finder</kbd> > select <kbd>Open Swift Class Diagram</kbd>
Configure
Optional:
<img width="512" alt="Preferences - Elements" src="https://user-images.githubusercontent.com/4176826/150644620-19f13392-08f2-4dba-b95a-0c9a002a5272.png"> <img width="512" alt="Preferences - Members" src="https://user-images.githubusercontent.com/4176826/150644626-7a566c4b-d795-432c-9a2e-ec29d2c1ba42.png"> <img width="512" alt="Preferences - Others" src="https://user-images.githubusercontent.com/4176826/218329326-6953799c-faa0-4de0-93a3-9d5856587e8c.png">Troubleshooting
The command "Open editable diagram in browser" is still busy
Xcode Source Code Extension initialization might take up ~ 30 seconds on initial launch.
If the prompt does not appear within 60 seconds
then check for a crash report related to XPC service in Console app of your MacOS.
<img width="1726" alt="CrashReportXPCServiceExample" src="https://user-images.githubusercontent.com/4176826/134083329-722a101a-4ec6-428b-9ee5-bcffec0784a8.png">If you see such crash report related to fatal error: Loading sourcekitd.framework/Versions/A/sourcekitd failed
please check the installation path of Xcode. If it's installed under /Applications/Xcode.app
, please run:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
If it's installed elsewhere, please replace the /Applications/Xcode.app
path in the command above with the location where you've installed Xcode.
Technical Details
This Source Editor Extension makes use of XPC service to run the app sandboxed and use SwiftPlantUML
(and its dependency SourceKitten
). Source Editor Extensions using SourceKitten
(either directly or indirectly) have to either run in a non-sandboxed app (and could not be distributed via the App Store) or use XPC service to outsource the use of SourceKitten
to a different process.
Acknowledgements
These awesome blog posts helped me to dive into Xcode Source Editor Extensions and XPC services