Better Programming

Advice for programmers.

Follow publication

Member-only story

Create Your First Swift Package Command Plugin

How to write and debug a Swift Package Command plugin

Riccardo Cipolleschi
Better Programming
Published in
9 min readSep 27, 2022

--

Photo by Jess Bailey on Unsplash

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…

--

--

Riccardo Cipolleschi
Riccardo Cipolleschi

Written by Riccardo Cipolleschi

Hey there, I’m Riccardo. Software engineer at Meta. I have a passion for iOS and I love to share my knowledge with others.

Responses (1)

Write a response