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 2.0 Basics An Introduction to Swift Programming Working With Constants

please help me !!! i dont understand this task. thank you.

i dont understand this task. please help me. thank you.

constants.swift
// Enter your code below

2 Answers

Hi Alexa,

A constant is a value that cannot be changed, unlike a variable which can.

The answer you are looking for here is,

let favDessert = "Ice Cream"

What I have done here is create a constant called favDessert and assigned it a value of type STRING. The value being Ice Cream. Swift has type inference, so it knows I have declared a string.

I could of also declared the type as follows,

let favDessert: String = "Ice Cream"

Hope this helps.

Marc

thank you sooo much you are awesome . its did help me and i re watch video . Regards, Alexa

Good, I'm glad.

To quickly further demonstrate the point. Here is an example I quickly put together.

var favDessert = "Ice Cream"
favDessert = "Cake"
print(favDessert)   //prints "Cake"
//
//
let newDessert = "Ice Cream"
newDessert = "Apple Pie" //throws an error as you cannot assign
                         //a new value to a constant.

Cheers, Marc