Member-only story
Create Your First Swift Package Command Plugin
How to write and debug a Swift Package Command plugin
This year, Apple released a new feature for the Swift Package Manager: Swift Package Plugins. We can now write two kinds of plugins that are automatically integrated with Xcode:
- Build (and pre-build) Plugins.
- Command Plugins.
I already talked about building plugins in a couple of articles: “Implement Your First Swift Package Build Plugin” and “How to Use Xcode Plugins in Your iOS App”.
Today, I want to share with you which steps are required to create a Command Plugin. The developer experience for these plugins is not great, so I want to share also a technique to debug them.
You can find more information about Swift Package Plugins in these WWDC22 videos: Meet Swift Package Plugins, Create Swift Package Plugins
The plugin
In this article, you are going to create a Command Plugin that generates some Swift code from a JSON specification.
To create a Command plugin, you need various pieces:
- A
Package.swift
file to define the structure of the Plugin. - A proper folder structure.
- A Swift
struct
that…