Home > front end >  Variable in swift
Variable in swift

Time:09-19

Is it safe to say that there are two types of variable in Swift ?

  1. variable
  2. Constant

Can constant be reffered to as a type of variable?

I ask this question because in programming world, variable can be define as data container (way to hold and store data).

Need more light shed on this to clear all doubt.

CodePudding user response:

A property can be a constant or a variable.

https://docs.swift.org/swift-book/LanguageGuide/Properties.html

But a variable can’t be a constant and a constant can’t be a variable.

CodePudding user response:

In Swift, a constant and a variable are two different types of data containers that are declared with different keywords, let and var respectively. So a constant is not a type of variable.

A variable is a data container whose value can be changed. A constant is a data container whose value is set once and can never be changed.

  • Related