Programming puzzles with Swift Playgrounds

Recent travel and the holidays gave me ample opportunity to dig into some programming puzzles that I’ve been meaning to try – in particular, to really walk through the swift language and programming tutorials using the Swift Playgrounds application (specifically on my iPad).


The content in the three Learn To Code playgrounds is incredibly well done. The sequences build on each other, refresh and play back what you’ve learned, and above all are fun. Even though I was already very familiar with the concepts, I enjoyed doing each of the exercises in the tutorials simpy because they were interesting, sometimes quite amusing, but mostly because they were fun!

The fact that it was available on an iPad was a definite bonus, letting me poke and prod at experiments and ideas while I was on a plane, or had some downtime for an hour. It was super easy to pick up, set back down, and then pick it back up a day or two later with no real loss of context or understanding.

A notable downside that I hit was that some of the help and documentation wasn’t available directly within the application (or apparently wasn’t cached by the application) and required the Internet and a browser to access.

For a newcomer to swift (or programming), when you did something egregious in playgrounds, the error messages could be exceptionally strange. That’s a place where you might be pretty confused, simply because the error messages don’t make a tremendous amount of sense. For example, if you torture a for loop with a typo:

for 1 in 1...3 {
    counter += 1

The first error message that comes available in a list of quite a few is “Expected Pattern”, which honestly means incredibly little even to me. The most useful message is the last one in the set: “Type ‘Int’ does not conform to protocol ‘Sequence'”, and even that assumes quite a bit of knowledge – like what a type is, what a protocol is, and that the 1…3 thing is leveraging a specific protocol called ‘Sequence’.

The whole concept of Playgrounds are very familar to me from time I spent in the Python community learning and using Python Notebooks (now more often called Jupyter notebooks) since they’re no longer just bound to the python language. The user interface metaphor is sort of a magic notebook, the first example I ever remember seeing was Mathematica in the computer labs at the University. These days, I see all sorts of scientific example papers that leverage this technology as a sort of “live and reproducible programming lab notebook”. A bit of a magic notebook where you can mix writing and programming freely.

Swift Playgrounds continues with this pattern, limited to the swift language, but still flexible enough that I could see some interesting capabilities for learning and teaching based on it. I haven’t yet really dug in to how to create playground content, certainly not to the amazing level that the Learning To Code playgrounds have enabled and embraced. I suspect it could make some really incredible walk-through API tutorials possible, which I’m looking forward to poking into more down the road.

In the mean time, I’ve got more puzzles to solve in the existing content…

UPDATE: Apple has the video showing off the Swift Playgrounds application available through their WWDC Videos, as well as a video from last year’s WWDC on how to author rich content for Playgrounds.

Published by heckj

Developer, author, and life-long student. Writes online at

%d bloggers like this: