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 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"]
favoriteSports.append("volleyball")

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)?