In this chapter, we will introduce a new environment where we can write and execute a swift code. We will also cover the following aspects of the swift playground −
Note − We will look only through those basic concepts, which we will be using in this tutorial, if you want to learn swift deeply, you can check our Swift Tutorial.
Playground is a tool provided with Xcode for executing the swift code. We will start by creating a new playground.
To create a swift playground, click on Xcode icon, and choose the first option, get started with a swift playground.
Give the name to your playground and select Platform as iOS. Let us name our playground as the Demo Playground. Click on Next.
These are the only steps you need to follow to make a Playground. The following screenshot shows the Playground.
|Sr.No||Basic Concepts & Description|
A variable is a memory / storage that our program can use to store and manipulate data. Each variable has a specific data type, which determines the size that a variable will occupy in memory.
A dictionary is a collection that stores values in a key value pair, i.e. the data stored in a dictionary is stored in a method where each value is related to a key. Here, every key is unique and cannot appear twice in the same dictionary.
Arrays are the data types that store the same type of data in an ordered list. The same value can appear at multiple indexes/Places in an array.
|4||Loops (Control Flow)
Swift provides a variety of Control Flow Statements. Loops are generally used to iterate over a condition or statement multiple times, until a Condition / Programmer’s need from that loop is satisfied.
|5||Classes and Objects
Classes are the general-purpose flexible constructs that are the building blocks of your program’s code.
Object is the term that is generally used to refer to instance of a class, so we can call it instance instead of objects.