A constant is a variable whose value can be assigned only once.
Constants are defined with a keyword let
. If you know that the value of a variable will not change it should be declared as a constant.
Syntax : let constantName = value
// Swift Tutorials 2014-15
// Constants in Swift
// Created by Code2care on 15/09/14.
// Copyright (c) 2014 Code2care. All rights reserved.
let contantVarable = 20
Program ended with exit code: 0
Constants Names :
You can assign any Unicode name to variable/constant names, this is not possible in many other porgramming languages. So you can use names
from almost any language like German, Hindi, Chinese, Japanese e.t.c. You can even have a Smiley as a constant/variable name.
Note that you cannot use arithmetic operators like + , - , * , % in a variable name, nor can the names start with a numeric value.
You can even define a variable name to a keyword that exists in Swift, just surround the name with back ticks (`) so that there is no conflict.