Swift Package Index: Try WriteFreely in a Swift Playground

Thanks to the Swift Package Index, getting the WriteFreely Swift package into an Xcode Playground is a button-click away!

The Swift Package Index is a search engine for packages that support the Swift Package Manager, built by Dave Verwer and Sven A. Schmidt.

I submitted the WriteFreely Swift Package sometime last week, and a few hours later it was indexed. Check out the page here! It shows plenty of very useful information — the current state of the project's repository, supported platforms and versions of Swift, and the README are all available for review on a single page. I didn't have to submit any of this information; it was simply pulled in, built, and tested from the main branch in the repository, and updates itself automatically every couple of hours or so.

But I think one of the most useful features in the index is the “Try in a Playground” button. Click it and, assuming you have the Swift Package Index Playgrounds app installed on your Mac, a little window will pop up prompting you to create a Playground:

Click the button and you'll be prompted to choose a location for the Playground. Once you do, the SPI Playgrounds app does a little work in the background...

...and the next thing you know, you've got an Xcode Playground launched, with the WriteFreely Swift Package imported and ready for testing!

(The sample code in the Playground is mine.)

I love this. It's great to provide some basic information in your README and your docs (which have been updated, by the way), but it's always much better to have a live code environment where developers can actually try out your library. It reminds me a lot of the work I did at Glitch. It's nice to find basic info on a NodeJS package on npm, but we always felt that the missing piece was getting developers from zero to hello world as fast as possible.

The Swift Package Index Playgrounds feature really helps with that.

One thing I'd love to see is a way to define some sample code that gets added to Content.swift, to help get developers started. I seem to recall (but can no longer find) a reference to some kind of YAML file (.spi.yml, maybe?) that could provide some configuration details for the Index when ingesting a Swift Package's repository, and having it point to, say, some sample code in a Swift file that gets imported into the Playground could be really useful.

UPDATE: Turns out, this can be done by adding an .arena-sample.swift file in your package! I've done this for the WriteFreely Package, and it works a treat:

(Be careful what you run, of course — I imagine it could also be dangerous to allow arbitrary code to be added, too.)

Anyhow, if you've been meaning to check out the WriteFreely Swift Package, this is a really useful way to start. Thanks to Dave and Sven for creating such a useful tool!


Enter your email to subscribe to updates:

You can also subscribe via RSS or follow @angelo@write.as on Mastodon.