index and element swift code example
Example 1: How to find index of list item in Swift?
let arr = ["a","b","c","a"]
let indexOfA = arr.firstIndex(of: "a") // 0
let indexOfB = arr.lastIndex(of: "a") // 3
Example 2: swift for loop index
for (index, object) in list.enumerated() {
print("Item at \(index): \(object)")
}