Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enumerate a zip array in swift 4 to get index for each object

Tags:

arrays

zip

swift4

I need to enumerate a zipped array to check index for each object from array. Below is my code please help me out.

for((index1, index2),(value1, value2)) in zip(array1, array2).enumerated() {
        // INDEX OF OBJECT
}
like image 239
Britto Thomas Avatar asked Oct 17 '25 11:10

Britto Thomas


1 Answers

Once you zip the array it is having only one index. Just use it as normal enumerations.

let arr1 = ["1","2","3"]
let arr2 = ["A","B"]
let arr3 = zip(arr1, arr2)
print(arr3)

for (index, (x,y)) in arr3.enumerated() {

    print(index, y)

}

enjoy!

like image 109
Saranjith Avatar answered Oct 19 '25 01:10

Saranjith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!