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


Create a constant named bestSmartphone and assign it the string "iPhone". Doesn't Work Right

let bestSmartphone: [String] = ["iPhone"]


Bummer! The bestSmartphone variable was expected to be a String, but it wasn't.

or even if I'm wrong let me know where is the mistake

5 Answers

Jake Adams
Jake Adams
1,608 Points

I'm not a huge fan of the existing answers just pasting the code you need to move on. No one explains why your code didn't work.

let bestSmartphone: [String] = ["iPhone"]

The type of bestSmartPhone here is an array of String values (that's what the square brackets indicate). So you could in this instance, have more than one best smart phone like this:

let bestSmartPhones: [String] = ["iPhone","Android"]

When you want to define a simple string, the only parts you need are the definition keyword (let vs var), the variable name, and the string value:

let bestSmartPhone = "Windows Phone"


Nice i like your answer not the samples but I'm totally agree with the coding :P

Nice i like your answer not the samples but I'm totally agree with the coding :P

Nathan Tallack
Nathan Tallack
22,159 Points

Yeah, I remember a challenge like this. It was a little annoying too, and I had to fiddle around in an xCode playground for a bit to get it working. This is the code I still have in my playground. I've commented inline in the code for you. :)

enum MobilePhone {
    case iPhone(String)  // Defining the string lets us use an associated value on this case.
    case Android(String)
    case Blackberry(String)
    case WindowsPhone(String)

let iPhone = MobilePhone.iPhone("6S")  // So here is where we get to set an associated value.  :)

I hope this helps. :)

is some more simpler i think its a bug in the courses system i found some bugs at least 9 months ago and they fixed but re-apear i wait to have support from them thanks a lot by the way your solution works but give me the same error

Nathan Tallack
Nathan Tallack
22,159 Points

Can you link to the challenge for me?

of course here you have it

I'm already try it accomplished in my mac or my iPad and does the same


Nathan Tallack
Nathan Tallack
22,159 Points

Oh right. This is a different challenge. Really strange that it starts talking about bestSmartphone string then goes onto a sports array. Maybe it is borked.

I managed to finish all three challenges with this code.

let bestSmartphone = "iPhone"

var favoriteSports = [ "football", "basketball", "tennis" ]


thats incredible but i was writing the declaration as a iPhone project required but is just swift lol :|

it get solved with this

let bestSmartphone: String = "iPhone"

P.S. Some times the answers are even easier than we think (always think KISS) lol