相关疑难解决方法(0)

使用NSPredicate根据NSDictionary键过滤NSArray

我有一系列字典.

我想基于密钥过滤数组.

我试过这个:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SPORT ==  %@)", @"Football"];

NSArray *filteredArray = [data filteredArrayUsingPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)

这不起作用,我没有结果.我想我做错了什么.我知道如果"SPORT"是一个ivar,这就是方法.我认为如果它是关键的话可能会有所不同.

然而,我无法找到一个例子.

谢谢


更新

我在我正在搜索的字符串周围添加了引号.

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SPORT ==  '%@')", @"Football"];
Run Code Online (Sandbox Code Playgroud)

它仍然无法正常工作.


更新2

解决了它.我实际上不得不删除单引号,这似乎与指南所说的相反.

我真正的问题是我有一个嵌套数组,我实际上并没有评估字典.骨头移动.

cocoa objective-c nsdictionary nsarray nspredicate

94
推荐指数
3
解决办法
10万
查看次数

使用谓词过滤NSDictionary

我正在使用一个NSDictionary本身包含字典的一些键及其值.格式如下,

{

"1" = {
        "key1" = "ss",
          "key2" = "rr",
          "name" = "nm"
     },
"2" = {
           "key1" = "tt",
          "key2" = "vv",
           "name" = "gf"
     },
"3" = {
           "key1" = "nm",
          "key2" = "vv",
           "name" = "gf"
     },
"4" = {
           "key1" = "tt",
          "key2" = "vv",
          "name" = "gf"
     },
}
Run Code Online (Sandbox Code Playgroud)

我需要使用NSPredicate来过滤key1应为"tt"且key2应为"vv"的情况.

iphone objective-c nsdictionary nspredicate

15
推荐指数
2
解决办法
2万
查看次数

标签 统计

nsdictionary ×2

nspredicate ×2

objective-c ×2

cocoa ×1

iphone ×1

nsarray ×1