Learn Swift 3 + Xcode Playground

Coding is key for education in information age. In the future many jobs will be replaced by computers. And what human will do, coding the computer to replace their job.

Why do we need computer to replace our job? Computer can do the same task over and over again without doing mistakes or feeling bored. But first we have to teach computer to what to do.

Today we will be learning to use Xcode Playground to learn Swift, it eases us to understand coding concept. Unlike traditional way, playground will show the result in-line without having to compile. It suites from just getting started to experienced developers.

Let’s get it started.

Creating a Swift Playground

To create a new Playground file, open the Xcode. Click File ▶ New ▶ Playground. Save it as ‘MyPlayground’ or any name you like at appropriate place.

Playground User Interface

Playground has 3 areas; editor, preview and print-out section like the image below.

When we write codes at editor, preview will show the result when we declare anything. On the Print-out area, it will show when we use print() function. He’re is an example code to show on the print-out area.

Let’s try to add some codes that declare somethings. In this case we will declare a String, Int, Double and Bool.

Right after you type the code at editor, immediately you will see on the preview like this after //. // is a comment-out feature, it will wipe out from computer when reading it. In this case the comment-out works as preview’s result.