Swift Playgrounds

October 2021

This part is about Apple’s Swift programming language and in particular the Playgrounds learning and experimentation environment.

There are many programming languages worth learning. But I found the educational approach of Playgrounds particularly interesting, especially with the two Playgrounds Learn to Code 1 and Learn to Code 2 - and that was worth doing an experiment for me and my seven-year-old daughter.

swift-learn-to-code

In the app Playgrounds the two Playgrounds Learn to Code 1 and 2.

Experiment: Teaching a child a high-level language.

Can a child who is just learning to read and write in elementary school learn a high-level language like Swift? Will it understand the basics without starting with Low-Code / No-Code languages like Scratch (external)?

I know what you can think: It depends on many aspects, but mainly on the child. We have decided that we want to try. It always depends on the attempt.

Of course, everything should be done according to instructions, in small steps, well explained and with a lot of patience and time.

Short and sweet.

Basically, I can already reveal this much, that the experiment was successful. After about 45 lessons (lasting between 45 minutes and 1 hour 30), my daughter successfully completed the first level Learn to Code 1 and it looked like this:

In this final challenge (Roll Right, Roll Left), she had to write a universal algorithm that was able to successfully make her hero collect all the gems and activate all the switches, regardless of the maze he had to go through.

secret-is-patience

To be honest, I have to admit that I had to give small help again and again. Sometimes she forgot the logical non-operator (!) or chose an “unfortunate” order of function calls, which made things unnecessarily difficult. Basically, though, she never ceased to amaze me. Her way of thinking was sometimes quite different from mine and in some cases more elegant, even more efficient. I noticed that she got better and better from lesson to lesson.

final-exercise-algorithms

Last puzzle world (final exercise: Roll Right, Roll Left) from Learn to Code 1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// MIT License (MIT) Copyright (c) 2021 Rosi Regner
// Challange: Roll Right, Roll Left (Algorithms)
func gemsAndSwitches() {
    if isOnGem {
        collectGem()
    }
    if isOnClosedSwitch {
        toggleSwitch()
    }
    if isOnGem && isBlocked {
        turnRight()
    } else if isBlocked && isBlockedRight {
        turnLeft()
    } else if isBlocked && isBlockedLeft {
        turnRight()
    } else if isBlocked{
        turnLeft()
    }
    moveForward()
}

while !isOnOpenSwitch {
    gemsAndSwitches()
}

Code to solve the final puzzle in Learn to Code 1.

On the following pages we present our solutions to the individual chapters/exercises.

Read next: Learn to Code 1 - Overview


Table of contents