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 trialMatt Conway
1,572 PointsVariable & String in Swift 2.0 Basics
In Challenge Task 1 of 2 in Swift 2.0 Basics, it says to declare a variable named "language" and to create a string "swift". Here is what I typed:
var = "language" str = "swift"
Got error message. What's wrong??
// Enter your code below
var = "language"
str = "swift"
1 Answer
Michael Reining
10,101 PointsHi Matt,
The challenge is asking for something a little different.
The syntax when you create a variable goes like this
var myVariableName // enter var followed by the variable name
var myString = "Enter String" // you can also initialize it with a String in one step
var myVariable: String // if you do not initialize it, you have to specify the type
Applying the above to the code challenge and you end up with this
// Enter your code below
var language = "Swift" // declare variable called language and assign it the string "Swift"
language = "Objective-C" // assign a new value to the language variable
I hope that helps,
Mike
PS: Thanks to the awesome resources on Team Treehouse, I launched my first app.
Now you can practice writing Swift code directly on your iPhone :-)