iOS Swift Basics An Introduction to Swift Programming Working With Constants

whats a constants main purpose

like how do you use it in code

  constant = favoriteDessert
string = ''pine apples''

2 Answers

Hi! You have to use "let" to declare a constant (not "constant") and remove the "=". Also, make sure you use "" instead of ' ' in your string. Hope that helps!

Michel Ortega
Michel Ortega
2,279 Points

The main purpose of a constant is to help with the memory while running the program. In this case, if you know that a value won't change, set it as a constant so the performance of the program (e.g. an app) is optimized.