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 Variables

Johnny Torres
Johnny Torres
1,338 Points

Am I close? var str = "language" str = "swift"

var str = "language"

str = "swift"

variables.swift
// Enter your code below

var str = "language"

3 Answers

Zachary Betz
Zachary Betz
10,413 Points

Johnny, you're close. You would write it like:

var language = "Swift"

Let's break this down a bit, though.

var is the keyword used when you are declaring a variable.

language is the name of the variable.

Swift is the value that you are assigning to the variable. In this case, Swift is a string, and you know this because it is surrounded in double quotes, i.e. "Swift"

Variables are values that CAN change so when you first set language value to "Swift", you can change it later on to something else, in this case "Objective-C". Your code should look like this:

var language = "Swift" language = "Objective-C"

I hope that I helped you! ;)

Zachary Betz
Zachary Betz
10,413 Points

Sure thing! Feel free to mark the answer as "best" if you're good to go.