Chapter 2

Variables and Constants

There are different initialization for constants and variables in Swift. Once initialized, a constant’s value cannot be updated but a variable can be updated. The following syntax is used to declare a constant.

Control Flow

If you are familiar with any programming language, you must know about if-else statements. Swift has two types of control flow statements. The if-else statements and the switch-case statements:

Arrays and Definitions

Arrays are a common type of variable in programming languages. In swift, initializing an array is extremely simple. An array is used to store multiple values in a single variable.

For Loop

A for loop can be used to retrieve all the values of an array but it can also be used for other purposes.

Optionals

If you wish to declare a variable that can have no value, you must make it an optional variable. Swift does not accept initialization without assigning a value.

Creating UI View

Now let’s try to play around with the UI and create a view element. It is the most basic element in the user interface and we will try to display an emoji and its meaning on a view pane.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store