But once the concepts are introduced, the lessons use the real terms for everything: call a function, loop commands, if statement, conditional code. Anything jargony in the instructions is colored red, and all you have to do is tap a red word for a definition.
The interface is split into two panels. The left side is text: Your challenge is explained at the top, with a space below for you to compose your program. The right side of the screen shows the results, with a big red Play button you can tap, labeled Run My Code. For the Learn to Code 1 lesson, I’m giving commands to Byte, a goofy cartoonish mascot who’s moving around a game board collecting gems and flipping switches. (Easter egg: Tap on Byte to change the character model; there are three to choose from.)
You’re given some commands to get started: You can tell Byte, for example to moveForward and turnLeft, which are both examples of how Swift commands really appear. But there’s no turnRight command out of the gate, so one of my first challenges was writing a turnRight function that combined three turnLeft commands. You can run the program after entering each command, or try to write the whole thing out at once by tapping the commands in the QuickType row or expanding the whole keyboard. The preview pane supports Multi-Touch, so I was able to scroll around the game world and zoom in and out to count, for example, how many squares Byte needed to move forward before he turned left.
Swift Playgrounds takes advantage of the iPad’s touchscreen interface. You can tap commands from the list along the bottom, pull up to get a full keyboard, or tap individual items in your code (like the For loop highlighted in red) for contextual items. (Click the image to enlarge.)
Learn to Code 2, which will launch with the final version of Swift Playgrounds this fall, has a different world than the gem-collecting, switch-flipping realm of Byte, which is meant to show that Swift’s tools can be used for tons of different applications, as well as to cut down on repetition.
Thinking like a coder
Swift Playgrounds encourages creative problem-solving—there isn’t one single solution, or even one “best” solution. You aren’t graded on how few lines you can use or how many functions you come up with. But the app does teach good coding habits like looking for patterns that repeat, and using descriptive names for functions so you can more easily remember what they do. If you break out ahead, say, adding a loop to your code before you are formally taught loops, the app gives you props for your advanced skills.
Sign up for MIS Asia eNewsletters.