ios - 如何在字典数组中搜索元素?

标签 ios arrays xcode search swift3

下面提到的是我的数组。我需要检查数组中是否存在条码 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/

相关文章:

ios - 从给定的 UIImage 创建有色 UIImage

ios - AVCaptureDevice videoZoomFactor 捏合缩放率

ios - CBCentralManager 未开机

c++ - 动态结构数组错误

java - 如何返回数组的元素编号?

java - 如何在不复制数据的情况下在 Java 中获取数组的子数组?

xcode - Git 在 macOS 更新后不工作 (xcrun : error: invalid active developer path (/Library/Developer/CommandLineTools)

ios - Swift 和 Xcode9 中的 VisualEffectView

ios - 如何向我的 UINavigationBar 添加文本?

c++ - 如何让 XCode 6 在调用 Debugger() 时不停止执行?