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 Build a Simple iPhone App with Swift Getting Started with Xcode A Swift Recap

Strings and arrays

I don't know whats wrong with my code. Can anyone solve this ? This is what te console said: The favoriteSports variable was expected to be a array of strings (aka [String]), but it wasn't.

let bestSmartphone = "iPhone" 
var favoriteSports: String = "football"

3 Answers

It should look like this:

let bestSmartphone = "iPhone"
var favoriteSports = ["football", "basketball", "tennis"]

Thank you verry much !

let bestSmartphone = "iPhone" 
var favoriteSports = ["football", "basketball", "baseball"]

An array is encased in []

What you wrote is:

var favoriteSports: String = "football" 

This just means that you want favorite sports array to be a explicative type of string with the value being football. In english what you said is "My favorite sports are football." Hope this helps.

David Maybach
David Maybach
2,092 Points

I was doing this:

var favoriteSports = ["football","basketball","tennis"]
println ("\(favoriteSports), volleyball")

Yeah that works, it will add volleyball to the array, but why not .append it to the array(well mutable array)?