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

Do I have to put quotation marks around a string?

Just a quick question I had.

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Yes. If you don't put quotation marks around a string, Swift is going to believe you're talking about another variable. It needs a way to differentiate between these two things:

var x = "aString"
var y = x
var z = aString

In the first line I assign the string "aString" to x. In the second, I assign the value of the variable x to y. The variable y will now also contain "aString". In the last line, though, you will receive an error because it's looking for a variable named aString, which doesn't exist.

Hope this helps! :sparkles:

Thanks so much!