Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,401 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,401 Points

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