I have 3 Animal Arrays:
let mammals = ["Dog", "Cat", "Bear"]
let fish = ["Clownfish", "Seahorse", "Scorpion Fish"]
let reptiles = ["Chameleon", "Snake", "Lizard"]
A button generates an animal at random, and then appends it to an allAnimals array. I'd like to be able to determine WHICH array the string (animal) came from.
I tried working with
allAnimals.contains()
however that explicitly takes a var as an argument. I can do allAnimals.contains("Seahorse") just fine. But I need to be able to check all arrays.
I also tried iterating through the array.
for i in allAnimals {
if i.contains(mammals){ print("Came from the Mammal array") }
else if i.contains(fish){ print("Came from the Fish array") }
else if i.contains(reptiles){ print("Came from the Reptiles array") }
}
That threw the error:
Cannot convert value of type '[String]' to expected argument type 'String'
How can I determine which array the random string came from?
The other way round