Loop through array with index


I have an array and want to iterate through all of its elements, by knowing the index of each element.


// Initialize the Array
var arr = ["one", "two", "three"]

// Iterate through the array
// keeping track of the elements' index

for (index,element) in arr.enumerate() {
    print("\(index) = \(element)")


Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)