Magic playground APIs?

I'm looking at some of the Apple-supplied sample playgrounds, like the "Answers" playgroundbook, and there seem to be APIs that are magically injected. For example, the first page of “Answers” is called “Text,” and contains:

show("What’s your name?")

let name = ask("Name")

show("Hi " + name)

Where do these show and ask functions come from? Are they documented someplace?


No they are just some helper functions that you can use. You can find them in other source file

They are not in any file that's visible from the Swift playgrounds app. If I dig into the playground package, I can find them in Contents/Modules/Book.playgroundmodule/Sources/PlaygroundAPI/AnswersPlayground.swift, but I guess that's something that's only visible from Xcode, when you're authoring these things?

What a confusing set-up!

I think it's on purpose because people who use Playground are usually swift beginners. The purpose is to learn the basic Swift grammar not the implementation.

The Playgroundbook format is documented here:


Not quite, but it's stashed away rather well. You can find it in the ...-menu under Advanced -> View Auxiliary Source Files, and drill down into the folder structure from there.

Sorry, I'm looking at the Playgrounds app on my Mac, and I don't see any such menu. What am I missing?

(I do see it on an iPad)

Terms of Service

Privacy Policy

Cookie Policy