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 trialsanterip
4,523 PointsSwift Basics - What is an Array? (Challenge)
I need to print the number of items in the array using println. I've tried to do this by assigning todo.count to a variable and then printing that variable with println. This kind of works in Xcode playgrounds but doesn't get me past the challenge.
Can you give me an example of what to do?
var todo = ["Learn Swift", "Build App", "Deploy App"]
var arrayItemCount = todo.count
println("\(arrayItemCount)")
2 Answers
Caleb Kleveter
Treehouse Moderator 37,862 PointsYou don't need a new variable, all you need is:
println(todo.count)
Jonas Kristensen
2,738 PointsTry to delete arrayItemCount and instead say println("(todo.count)")
Hmmm... I can't make backslash in a comment, but you know what i mean
santerip
4,523 PointsHey, yeah I know what you mean. This worked without the backslash too and you could also just write println(todo.count)
Thanks for the answer!
santerip
4,523 Pointssanterip
4,523 PointsThat's probably the best way to do it. Thanks a lot!
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsGlad I could help!