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?

Omotayo Olawepo
Omotayo Olawepo
2,803 Points

help with code . can't get it to work

using println()

arrays.swift
var todo = ["Learn Swift","Build App","Deploy App"]
println("\(todo.count)/") 

1 Answer

You're close. I think you're sort of trying to use string interpolation, however, you want use that when you want to print a parameter you pass to a function or use a variable inside a longer string. In this case, all you need to do is use .count on todo:

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

To use string interpolation in something like this you can:

var todo = ["Learn Swift", "Build App", "Deploy App"]
print("I have \(todo.count) things to do today. These are the things I have to do today \(todo)")

This allows your code as well to be easily built upon. I could have just as easily used "I have 3 things to do today" as the String, but what if I added another item to me todo array? I would have to remember that I have to manually update the String to "I have 4 things to do...".

Omotayo Olawepo
Omotayo Olawepo
2,803 Points

thanks dude . i get it now