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 Basics (retired) Collections What is an Array?

how is this the second line of code not right, I tried it in Xcode and it printed 3


var todo: [String] = ["Learn Swift", "Build App", "Deploy App"]

2 Answers

Faisal Alsheikh
Faisal Alsheikh
8,841 Points

Try this:


Note that your array has 3 strings, ur first string is indexed at 0 then 1 then 2

Println(3) is only printing out the Int 3 into the console...

J.D. Sandifer
J.D. Sandifer
18,813 Points

It looks like you're doing the "print the number of items in the array" challenge - is that right?

If so, the problem is that I believe that the challenge looks to see that you're correctly doing the challenge, not just that you get the right answer.

In other words, even though "3" is the correct answer, you're not getting it the correct way.

Here is my suggestion to fix your code - note the comment below:

var todo: [String] = ["Learn Swift", "Build App", "Deploy App"]
println(todo.count)   // this prints out a 3 because there are 3 items in the array