Playgrounds for Libraries

I recently noticed (in the Interstellar project) that you can include a Playground with your Swift library. I think this is a great way to provide some documentation and examples, and also to give a new user a way to easily start experimenting with using the library.

So, this is my attempt to raise awareness about this, and to ask library authors to include a Playground in their projects.

And, to lead by example, I just opend a pull request to add this to Soroush Khanlou’s Promise library.

How To

It turns out to be pretty easy to do this. If you simply include the Playground in your workspace (or even just .xcodeproj), and then you make sure the .framework has been built (e.g. by building a scheme in your project that includes the framework), then you can simply import MyFramework at the top of your Playground, and use the public API. I’m guessing there is some magic that Xcode is doing to make this build/link correctly.