Variable, Constant and Naming Rules
Arithmetic Operations and Compound Assignment
Data Types and Type conversion
String (Concatenation and Interpolation)
Boolean, Comparison operators and Logical Operators
While Loop and Repeat While
Continue, Break and Fallthrough
Tested on: Xcode 12.2, Swift 5.3
Playground allows you to quickly write and test code without creating an complete application. This is very useful if you want to test out your algorithm before going into your app project. In this Swift Playground Reference, the following topics will be cover :
When you open Xcode, it will greet you with a welcome screen that looks like the image below. If you don't see this, probably you have unchecked Show this window when Xcode lauches. However, this screen it not important if you want to open Swift Playground.
To create a Swift Playground, go to File > New > Playground or type option + shift + command + N and a playground screen will appear for you to choose a template.
The selection allows you to choose the type of template you want to create the playground. The options available are iOS, macOS, tvOS. Each platform come with it own environment.
In most cases and for the purpose of all the courses and reference in Appdevelopments.com, you will use iOS and choose a Blank template. Click next to continue. Xcode will ask you to name the playground and save it to an location.
Among all these toggle, the most important one are Activity View, Play / Pause Button, Result and Debug Area. You will understand the rest of the toggle, when you use playground more often.
Turning on Line Number. You can turn on line number by going Xcode > Preferences > Text Editing > Line Numbers and check the line number box. Line number is useful when you want to refer to the part or line of the code.
Playground excute code from top to bottom and the play button at each line of the code enable you to run the code from the beginning to that line of code. Once Xcode execution is finished, the status is shown on the Activity viewer.
Moreover, you can use the Play / Pause Button to run the entire playground or stop it. You can change the setting to Automatically Run by long pressing on it.