Swift Tips: How to use enumerated() in array

Swift Tips: How to use enumerated() in array

This is very useful if you are trying to manipulate in old school C, C++ way. Here's an example: That will print "Found Hulk at position 0", "Found Thor at position 1", and "Fou...

Alok Choudhary
Austin, TX
1 min read

This is very useful if you are trying to manipulate in old school C, C++ way.

Here’s an example:

let array = ["Hulk", "Thor", "Spidy"]

for (index, item) in array.enumerated() {
print("Found \(item) at position \(index)")
}

That will print “Found Hulk at position 0”, “Found Thor at position 1”, and “Found Spidy at position 2”.

Link copied to clipboard!

Made with ❤️ in Austin.

Copyright © 2026