I have two arrays with different types (classes) and amount of items there. When I try to loop through them, I loop as much times as much items in smaller array. I need it to loop through both and when smaller ends, larger one continue to loop. Hope to see some suggestions.
So, I have two arrays:
var humanArray = [human, cook, manager, fighter, astronaut]
and:
let alienArray = [martian, twixian, snikersian]
They are different classes:
let human = People(name: "John Dou", height: 180, weight: 80, gender: "male")
and:
let martian = Martian(numberOfLegs: 1, colorOfSkin: .red)
then I loop through them:
for (hum, al) in zip(humanArray, alienArray) {
print("""
\(hum.TypeName) \(hum.name),
\(hum.TypeName) \(hum.height),
\(hum.TypeName) \(hum.weight),
\(hum.TypeName) \(hum.gender),
\(al.TypeName) \(al.numberOfLegs),
\(al.TypeName) \(al.colorOfSkin)
""")
hum.say()
al.say()
}
So what should I do to get all the 5 iterations? Or how to do such thing (loop over two arrays) without "zip"? Without it, I have an error: Yes, they are ignored, but how to do this without "zip"? I have an error: "Type '([People], [Martian])' does not conform to protocol 'Sequence'".
My question is different than questions, that was asked before, because I have two arrays with different amount of items. And solutions, provided there, are not appropriate.