Swift – Constant And Variable

We will learn about swift constants and variables.

Constants and Variables : 

What : Constants and variables associate a name (such as name or colour) with a value of a particular type (such as the string "Amit" or the string "green") respectively. The value of a constant cannot be changed once it is set, whereas a variable can be set to a different value in the future.

When : Almost each and every phase of programming we have to use constants and variables.

Constant Declaration : 

Let’s declare a constant with name “name” and value “Amit”.

Let’s declare a constant of type String first, and then assign it a value “Amit”

Note : We can not change a constant value later. For example if i want to change constant from “Amit” to “Alok”, we can not.

Variable Declaration : 

Let’s declare a variable with name “name” and value “Amit”.

Let’s declare a variable of type String first, and then assign it a value “Amit”

Note : We can change a variable value any time in programming phase. For example if i want to change variable from “Amit” to “Alok”, we can change it easily.

2 thoughts on “Swift – Constant And Variable”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.