dabrahams
(Dave Abrahams)
1
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?
Thanks,
Dave
Kyle-Ye
(Kyle)
2
No they are just some helper functions that you can use. You can find them in other source file
dabrahams
(Dave Abrahams)
3
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!
Kyle-Ye
(Kyle)
4
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.
hborla
(Holly Borla)
5
The Playgroundbook format is documented here:
4 Likes
ahti
(Lukas Stabe 🙃)
6
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.
dabrahams
(Dave Abrahams)
7
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)