Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Basics An Introduction to Swift Programming Working With Constants

whats a constants main purpose

like how do you use it in code

constants.swift
  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.