say i have a very simple Person class
class Person {
var name:String
init(name:String) {
self.name = name
}
}
QUESTION: how do i check if people.list contains the instance alex, please?
class Person is a reference type, and var alex is a reference
to the object storage. The identical-to operator ===
checks if two constants or variables refer to the same instance
of a class.
Therefore, in order to check if the list contains a
specific instance, use the predicate-based contains()
method, and compare instances with ===:
if people.list.contains({ $0 === alex }) {
// ...
}