Index where doesn't return Int ?

Array.index(where: { $0 == ... } returns "Array<Element>.Index" instead of an Int. Is there a way to get an Int ?


Thanks.

Accepted Reply

I tested the following


let listOfNames = ["aa", "bb", "cc"]
let index = listOfNames.index(where: { $0 == "bb" }) ?? -1          // becasue returns optional

print(index)


I get 1


What is your issue ?

Replies

I tested the following


let listOfNames = ["aa", "bb", "cc"]
let index = listOfNames.index(where: { $0 == "bb" }) ?? -1          // becasue returns optional

print(index)


I get 1


What is your issue ?

Works, thanks.