In Swift, there are two types of values:
- Constants. These are immutable variables.
- Variables. These are mutable variables.
To declare constants/variables in Swift:
- let is used to declare an immutable constant. You cannot change its value of it later.
- var is used to create a mutable variable that you can change later.
For example, to create a constant value in Swift, use the let keyword:
let num = 100.0
And to create a variable in Swift, use the var keyword:
var x = 200
Swift advises you to create constants whenever possible. You can see this in action when Xcode shows you warnings about using var.
Using constant values is meaningful when you want to declare variables that are not supposed to change. When you make them constants using the let keyword, it is impossible to accidentally change them in the future.
Further Reading
About the Author
- I'm an entrepreneur and a blogger from Finland. My goal is to make coding and tech easier for you with comprehensive guides and reviews.
Recent Posts
Artificial Intelligence2023.05.16Humata AI Review (2023): Best PDF Analyzer (to Understand Files)
Python2023.05.139 Tips to Use ChatGPT to Write Code (in 2023)
Artificial Intelligence2023.04.1114 Best AI Website Builders of 2023 (Free & Paid Solutions)
JavaScript2023.02.16How to Pass a Variable from HTML Page to Another (w/ JavaScript)
At the beginning, I was still puzzled. Since I read your article, I have been very impressed. It has provided a lot of innovative ideas for my thesis related to gate.io. Thank u. But I still have some doubts, can you help me? Thanks.
After reading your article, I have some doubts about gate.io. I don’t know if you’re free? I would like to consult with you. thank you.