Textlogo_codingem_white

Programming tips for everyone

What is the Difference between Let and Var in Swift?

let is used to declare a constant that you cannot change later. var is used to create a variable that you may change later.

For example, to create a constant, use let as follows:

let num = 100.0

And to create a variable, use var like this:

var x = 200


Notice how Swift strongly advices you to create constants whenever possible by showing you warnings in Xcode. This makes sense, because if you think about it, all it tries to do is to prevent you from accidentally changing values that are not meant to be changed.

Thanks for reading. Happy Coding!

You May Find Insightful

Swift – Upgrade Your Skills with These 5 Tips

iOS Development Tips in 2021

Share on facebook
Share on twitter
Share on linkedin

Related Articles

Artturi Jalli

Technical Writer

Entrepreneur, Software Engineer, Mobile App Dev, MSc Physics Student, And Tech Enthusiast from Finland

artturi@codingem.com

My Personal Favorites
Sponsor

Buy an Online Course

Lorem ipsum dolor sit amet consectetur adipiscing elit dolor
Explore Categories

Favorites