Learn Swift in 24 hours
Tap to find out how much you can master in so little time.
Coding is a fundamental skill, and one we (sadly) weren't taught in school. But the App Store is packed with incredible training tools – so we decided to enter into the unknown and try our hand at finally demystifying the practice of code. Spoiler alert! – it's surprisingly easy to understand.
To start, we tried the iPad app Swift Playgrounds which turns coding into a game, hiding informative lessons into fun new puzzles that advance your skill levels. Similar to full-immersion language learning, after a brief introduction Playgrounds throws you right into the thick of it, asking you to solve smaller puzzles to move the loveable mascot, Byte, around the map.
Rather than getting bogged down by the various syntax involved, Playgrounds focuses on helping you to solving pieces of code that action your character to move. You'll soon feel like a coding whizz as you watch Byte manoeuvring to your instructions!
Like an immersive foreign-language class, Swift Playgrounds throws you into the thick of it so you quickly master the basics. Swift Playgrounds presents you with a split screen: one half shows a text area where you enter Swift commands to control an adorable one-eyed creature named Byte. He appears on the other half of the screen in a game-like world. Try running the moveForward() command. Byte moves forward, and you’re coding already.
Learn real coding the fun way
In this session, make your code more concise by grouping a series of commands to create a function.
After learning how to break big problems into small steps (a process called decomposition), you’ll create a function called turnAround. As the puzzles get more complex, turnAround() saves a ton of time. Although solving a puzzle is occasionally a cinch, more often you’ll have to think through every step, experiment, and fail. Swift Playgrounds makes it easier to see the error of your ways by letting your programme run at different speeds: a slow mode highlights each snippet of code as Byte performs it. The super-fast version is handy when you just want to see if your programme works or not.
After a while, we then began to learn new tools to make our code more efficient. We can write a Function, which repeats a series of commands. We can use a Loop to determine how many times Byte will execute our commands and functions. And then we learn about Conditional Code – which lets us plan for all sorts of circumstance. For example, If Byte is standing under a Gem, we can make him Collect Gem. If he's not, we can use else to help him keep moving.
After five hours, we learn about Logical Operators – which allow you to combine a set of circumstances. If Byte is NOT standing under a Gem And he's on a Switch, we can make him toggle the switch. These tools are surprisingly robust, but to write clean solutions, you really have to think through a problem from beginning to end.
Swift Playgrounds does an amazing job of combining the lessons we've learned, so even as we're learning new Logical Operators, we're combining them with functions, loops, and if statements. Soon, it's like our little friend is making his own decisions – but of course he's not.
Although it takes time to become exceptionally precise with the code you create; in 24 hours, we were able to learn some of the basics to help solve puzzles and understand where we had made errors.
Maybe this coding thing isn't inscrutable after all.
Now for conditional code, which lets Byte react to information. For example, you can make Byte collect a gem only if he’s standing under it.
Sometimes you’ll write conditional code that doesn’t have the effect you intended. When Byte fails because of something you wrote, it’s hard not to feel bad for him (he frowns and gets all sad). That said, it’s also funny to watch him walk endlessly into a wall.
In your sixth hour, learn about logical operators. These allow Byte to consider different circumstances in combination. Certain conditions, like ‘isOnGem’, result in a answer that’s either true or false (called a Boolean). This means you can make Byte do one thing if a condition is true, another if it’s false. It’s a key moment. Until now, you’ve been able to make Byte walk, but this is the first time he’s making his own decisions. OK, you programmed him to do it, but your little friend is getting smarter (and so are you).
Now you may begin to see how the apps you use every day might employ the same rudimentary commands you’ve learned. For example, if someone launches an app for the first time, display a tutorial.
Logical operators are complex – and increasingly, so are the puzzles and your code. If you start a new puzzle and it seems there’s no way to solve it with what you’ve learned, try breaking it down into smaller chunks.
One lesson to take to heart: it’s important to be precise. Programming can feel like speaking to a child who takes everything literally. (“Well, you said go right. You didn’t say anything about not walking into the wall!”)
By the end of eight hours, there’s still plenty to learn. Hopefully this start has been promising enough to inspire you to continue the journey.