I can't figure out how to find index of object in array. For example I have this data structure:
class Person {
var name: String
var age: Int
init(name personName: String, age personAge: Int) {
self.name = personName
self.age = personAge
}
}
let person1 = Person(name: "person1", age: 34)
let person2 = Person(name: "person2", age: 30)
...
var personsArray = [person1, person2, ...]
I tried to use personsArray.index(where: ....)
but I don't understand how to use it. index(of: ...)
doesn't work. I think because personsArray
doesn't conform to Equatable
protocol...