下面提到的是我的数组。我需要检查数组中是否存在条码 8901058847857 或条码 xxxxxxxxxxx。
(
{
barcode = 8901058847857;
image = (
);
name = "Maggi Hot Heads";
productTotal = "60.00";
quantity = 3;
},
{
barcode = 8901491101837;
image = (
);
name = "Lays Classic Salted";
productTotal = "20.00";
quantity = 1;
}
)
我尝试使用 array.contains 或 array.elements 但它不起作用,因为条形码存在于数组中。
最佳答案
** 试试这个 **
// Put your key in predicate that is "barcode"
var namePredicate = NSPredicate(format: "barcode contains[c] %@",searchString);
let filteredArray = arrayOfDict.filter { namePredicate.evaluate(with: $0) };
print("names = ,\(filteredArray)")
关于ios - 如何在字典数组中搜索元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43486691/