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?

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

arrays.swift
var todo = ["Learn Swift", "Build App", "Deploy App"]

var arrayItemCount = todo.count

println("\(arrayItemCount)")

2 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

You don't need a new variable, all you need is:

println(todo.count)

That's probably the best way to do it. Thanks a lot!

Try to delete arrayItemCount and instead say println("(todo.count)")

Hmmm... I can't make backslash in a comment, but you know what i mean

Hey, 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!