I'm trying to verify if an object that comes from an API already exists in my array of objects, but I'm not being able to do that verification, Xcode keeps telling me that
Binary operator '==' cannot be applied to two 'Cidades' operands
and my code is:
var cidades = [Cidades]()
func findAllCidades(completion: @escaping CompletionHandler) {
Alamofire.request(URL_CIDADESATIVAS, method: .get, parameters: nil, encoding: JSONEncoding.default).responseJSON { (response) in
if response.result.error == nil {
guard let data = response.data else {return}
if let json = try? JSON(data: data) {
let results = json["results"].array
for item in results! {
let name = item["nome"].stringValue
let estado = item["estado"].stringValue
let id = item["id"].intValue
let cidade = Cidades(id: id, nome: name, estado: estado)
if(!self.cidades.index(where: { $0 == cidade})){
self.cidades.append(cidade)
}
}
completion(true)
}
} else {
completion(false)
debugPrint(response.result.error as Any)
}
}
}