Get Coding, Fast
Tap to find out how easy Swift programming is to master.
If you’ve been meaning to learn to code but haven’t had the time, there’s good news: By devoting just one hour a day over eight days to learning Swift, you can get surprisingly far.
Your guide: the iPad-only app Swift Playgrounds, which turns coding into a game by presenting each lesson as a puzzle.
Here’s what to expect:
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.
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 program 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 program works or not.
New tool: “Loop" decides how many times Byte will execute a command. This will come in handy.
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 you’re inspired to continue the journey.