Over the years, I have explored a lot of different programming languages, specifically JavaScript, Ruby, PHP, Python, Apex, GML, etc.

In 2014, Apple released the Swift programming language. I have always been intrigued by Swift but lacked the reason and/or time to start the learning process.

Conveniently, my son (aged 4) is now at an age where he can start to understand the basics of coding. Therefore, I thought I would use this as an excuse for us to explore the Swift programming language together, looking to validate Apple’s claim that Swift is easy to learn.

What is Swift?

Swift is a general-purpose, multi-paradigm, compiled programming language.

As the name suggests, Swift has a focus on speed, specifically the enablement of rapid application development, as well as code performance. For example, when compared against Objective-C, Swift is a clean, expressive and concise language with a simple syntax that makes it easy to read and write. It is also up to 40% faster than Objective-C, with clear community guidance on how to deliver highly-optimised code.

Alongside speed, Swift targets safety, with a strong typing system and robust error handling. This further enables rapid application development, as errors can be identified in real-time, resulting in a shorter feedback loop, reducing the risk of production issues.

In 2015, Apple made Swift open-source, which alongside the continued growth of the Apple ecosystem (e.g. macOS, iOS, WatchOS, tvOS) has contributed to its steady increase in popularity.

Therefore, alongside JavaScript and Python, I believe Swift is a viable programming language for anyone looking to learn to code.

What is Swift Playgrounds?

Swift Playgrounds is a REPL (Read–Eval–Print–Loop) development environment for Mac and iPad. This development paradigm aims to enable a simple, interactive programming environment that takes single user inputs, evaluates them, and returns the result to the user in real-time.

Therefore, Swift Playgrounds can be a powerful education and testing tool, which Apple has incentivised through a collection of highly interactive lessons (grouped as playgrounds).

Swift Playgrounds

Swift Playgrounds is available for free and includes a wide range of lessons, which can be completed offline.

Using Swift Playgrounds

Recognising the interactive nature of Swift Playgrounds, it felt like the perfect environment for my son (aged 4) and I to learn Swift together.

Alongside Swift Playgrounds, Apple has produced some excellent supporting materials, covering all ages and levels of experience. To get started, I would recommend reviewing the content found on “Apple Education - Teaching Code” website. Specifically, the “Curriculum Guide”, which structures the leaning, providing useful tips and tricks.

The curriculum states that the “Learn to Code” playground (created by Apple) targets ages 10+, which I feel is a fair guide. However, even at 4, my son and I were able to complete the “Learn to Code 1 (Fundamentals of Swift)” playground, which includes the following lessons.

  • Chapter 1 - Commands: Students learn about the importance of clear, precise commands.

  • Chapter 2 - Functions: Students explore the power of functions by grouping commands into a definition they can use over and over.

  • Chapter 3 - For Loops: Students recognise patterns in the world around them and in their code, and learn how to write more efficient code using loops.

  • Chapter 5 - Conditional Code: Students explore how Boolean logic helps us make decisions in our everyday lives and in code.

  • Chapter 6 - Logical Operators: Students explore scenarios that require them to consider multiple factors before they make a decision.

  • Chapter 7 - While Loops: Students explore the power of a while loop for repeating a section of code multiple times until a condition is met.

  • Chapter 8 - Algorithms: Students learn how an algorithm is a set of rules and instructions used to solve a problem.

Like most children, my son will look for any opportunity to play with a smartphone or tablet. Therefore, it did not take a lot of convincing to get him involved.

In my opinion, the best part about Swift Playgrounds is the fun and highly interactive visuals, which are structured as a set of increasingly difficult puzzles (like a game). Each puzzle adds a new element or concept, which progressively increase in complexity. For example, you start by issuing one command, before adding multiple commands.

My son immediately understood the concept and (with some gentle guidance) was able to quickly move through the opening chapter, clearly building confidence as he completed each puzzle.

Swift Playgrounds

At 4, it is worth noting that my son has only just started school, therefore cannot read or write. When writing code, you would assume this would be a hindrance, however, Swift Playgrounds provides handy keyboard shortcuts (essentially making the puzzles multiple choice).

Swift Playgrounds

Therefore, although my son cannot read the words, he can identify key letters (helped by the use of camelCase). For example, with “moveForward()”, he would look for the “m” and “F” vs. turnLeft() where he would identify the “t” and “L”. I would provide support where required and verbalise the words and key concepts as we progressed.

The video below is a short clip of my son working through one of the puzzles.

Overall, we were able to progress through the first five chapters with relative ease, at which point the complexity did increase to a level that required a greater amount of support. Unsurprisingly, as the puzzles became more complex, my son’s interest and enthusiasm began to wane. He was perfectly capable of completing the challenge but lacked the patience to work through the problem. Therefore, I feel Apple’s 10+ age guidance is a good benchmark.

The photo below is my son proudly showcasing his first “function” (excuse the crazy look).

Swift Playgrounds

Having reviewed the “Learn to Code 2 (Beyond the Basics)” playground, I do not believe this is viable for my son (yet), therefore we will continue to refine our skills by repeating the fundamentals.

Conclusion

Overall, I commend Apple for their commitment to code and programming, especially their goal of making it fun, engaging and accessible to all ages.

In my experience, the “Learn to Code” playgrounds successfully support the development of core coding skills and programming vocabulary (helped by the concise and expressive syntax of Swift). For example, my son cannot code, but he does now understand some of the basic concepts (even if it is unconsciously). These concepts are critical when looking to learn more advanced programming techniques, as well as support the growth of other core skills such as maths, reading and writing.

The only area of improvement I have observed would be the jump from core coding concepts to real-world application development. For example, the first time a new programmer attempts to apply core concepts to develop a real application, using a full IDE like Xcode, can be very daunting.

Apple provides resources to support application development, but they switch from fun and interactive learning to heavyweight documents and/or README files associated with code repositories. In my opinion, this can be a big jump, which I would like to see Apple attempt to mitigate (maybe via a simplified Xcode for iOS).

Finally, it worth noting that Swift Playgrounds also supports third-party playgrounds, which is great to see! I have downloaded the Sphero and Tello playgrounds, which support direct interaction with physical hardware, allowing anyone to programme a drone, etc. My only criticism is that these playgrounds are not always well maintained (not the fault of Apple), meaning that certain functionality can stop working with newer released of iOS, etc.

In conclusion, I am very impressed with Swift and Swift Playgrounds and would certainly recommend the programming language to anyone looking to learn to code.