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

Britt Lewis
Britt Lewis
2,315 Points

This question is broken. Count is a read-only property on arrays, not a method. Can't pass

I get the error that I should call the count method on the array. Neither interpolation of accessing the count property nor of a new variable storing the value of the property work. It seems to be expecting a method call (including parens, perhaps?), but count is a property on Array, not a method -- and I suspect therefore it won't compile, as there is no method count.

2 Answers

So I'm assuming your two tries looked something like this?

var todo = ["Learning Swift", "Build App", "Deploy App"]
println("\(todo.count)")

and then you tried something like:

//This could work, but it's not what the challenge wants
var todo = ["Learning Swift", "Build App", "Deploy App"]
var temp = todo.count
println(temp)

What you're missing is, println doesn't need interpolated strings when passing in something that will return a value by itself. Here's what the challenge wants:

var todo = ["Learning Swift", "Build App", "Deploy App"]
println(todo.count) //equivalent to println(3)
Britt Lewis
Britt Lewis
2,315 Points

Yep, that's exactly what I was doing. Thanks for clearing that up, cuckoo. (Also, those code snippets look great! Treehouse has come a long way since I last used it).

So is there logic preventing the interpolated response from being valid? Do the challenges compare values and output or look for specific code?