My Playground Secrets and Power Tips book covers nearly everything you need to know about 1.x and 2.x playgrounds including many of the new features being discussed this morning. I’m already working on updating the book for 2.x.
Here are some thoughts about the new 2.x-only features in playgrounds.
Playgrounds as Books. Playgrounds are headed in the right direction with their newly-introduced multi-page support and links, but they’re not quite there yet. If nothing else, they do not yet offer options to disable runs or to “run now”, which you really need in a system that can consume a lot of CPU. Nor do they offer a “reset to original” feature, which is critical for examples.
I personally would love to see integrated controls directly in the playground to enable users to tweak code parameters. I’ve mocked up workarounds but native elements would be best.
How to add pages. File > New > Playground Page. The page is created with basic embedded navigation, e.g. [Next](@next) for the next page and [Previous](@previous) to go back. Other keywords are @first and @last, plus you can name pages, e.g. [Go to Overview](Overview).
Fun fact. Each page runs as a separate application. Take a look at NSBundle’s executable path and see for yourself.
Assistant vs Debug Area. Playgrounds now use the standard debug area instead of an assistant window. I had to update my personal keyboard shortcuts from Assistant Editor > Show Assistant Editor to View > Debug Area > Show Debug Area.
CustomPlaygroundQuickLookable. I don’t recall this being there before and I need to explore more closely. I believe this is a playground variation on Quick Look. Instead of or in addition to implementing debugQuickLookObject(), you add customPlaygroundQuickLook() and return a PlaygroundQuickLook item.
Apple writes:
A type that explicitly supplies its own PlaygroundQuickLook. Instances of any type can be `reflect`’ed upon, but if you are not satisfied with the `Mirror` supplied for your type by default, you can make it conform to `CustomReflectable` and return a custom `Mirror`.
Upgrading Swift. You can migrate playground code using Edit > Convert > To Latest Swift Syntax just as you would in a project. It’s generally easier to migrate in non-playground projects when possible, so keep that in mind. Playgrounds aren’t the most stable or friendly of places, especially in early betas.
Finding Playgrounds. As far as I can tell, playgrounds still do not have a spotlight importer, so locating stuff can be maddening. (“I know I was working on that feature in a playground…now where is it?”) Please file a radar and ask Apple to enable spotlight so it can search inside playground bundles.
Comments are closed.