The for-in loop iterates over a set of elements and provides the actual element, not its index at each iteration. Thus, your loop should be rewritten as:
for contact in contacts { println("\(contact.name)")
Note that this line:
var count: Int = 0
does not affect your code, because the count variable in the for-in overridden and visible to the code block nested inside the loop.
If you still want to play with indexes, you need to change your loop like:
for var count = 0; count < contacts.count; ++count {
or
for count in 0..<contacts.count {
Finally, if you need both an index and a value, perhaps the easiest way is to use the global enumerate function, which returns a list (index, value) of tuples:
for (index, contact) in enumerate(contacts) { println("Index: \(index)") println("Value: \(contact)") }
source share