У меня UICollectionView
содержит: UIlabel
и UIButton
(текст в метках взят из API)
![enter image description here](https://i.stack.imgur.com/5GhG9.png)
когда я нажимаю UIButton
текст из UIlabel
и CostLbl сохраняются в UserDefaults.standard.array (forKey: "car")
let imageData = UIImageJPEGRepresentation(image.image!, 1.0) as NSData?
let newValues = ["name": self.nameLbl.text ?? "", "price": self.costLbl.text ?? "", "image": imageData]
var mArray = UserDefaults.standard.array(forKey: "car") as? [[String: Any]]
maAr?.append(newValues)
Вопрос: при нажатии UIButton
необходимо проверить, находится ли текст из UIlabel
в массиве (forKey: "car"), если нет - можно сохранить для ключа, и если текст уже находится в массиве (forKey: "автомобиль") нельзя добавить в массив
Я написал, как предложил Вадиан
var maAr = UserDefaults.standard.array(forKey: "car") as? [[String: Any]] ?? []
if !maAr.contains(where: newValues) {
maAr.append(newValues)
def.set(maAr, forKey: "car")
}
но ошибка отлова до (where: newValues)
-
Cannot convert value of type '[String : Any]' to expected argument type '([String : Any]) throws -> Bool'
Как это можно изменить?