从Dictionary获取数组项的值搜索

时间:2015-07-16 08:00:56

标签: ios objective-c

我在这里有值列表。

NSArray *allvalues = [subjectValue allValues]; // subjectValue is Mutable dictionary

日志打印如下,

allvalues: (
        (
        "service3@citicorp.com",
        "IMPORTANT - Documents required"
    ),
        (
        LinkedIn,
        "Do you know Daniel?"
    ),
        (
        “Dave steve”,
        "RE: Development"
    ),
        (
        Angelour TB,
        "Score High on it”
    ),
        (
        MyntraCavin,
        "EORS: Sneak Peek!"
    )
)

我想使用搜索功能并查找此数组中的内容。 我试过了,

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[c] %@",searchText];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY SELF == %@", searchText];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF == %@", searchText];

获取过滤后的数组值,

    NSArray *filteredValues = [allvalues filteredArrayUsingPredicate:predicate];
    NSSet *keys = [subjectValue keysOfEntriesPassingTest:^BOOL(id key, id obj, BOOL *stop) {
            return [filteredValues containsObject:obj];
        }];
    NSLog(@"subjectValue key desc: %@", keys.description);
    if (keys!=nil)
        filteredUidArray = [keys allObjects];

但是,过滤的值总是在上面的3个谓词搜索中返回nil。有人可以建议我如何获得这种数组格式allvalues的过滤值。

1 个答案:

答案 0 :(得分:0)

您过度使用集合类。而是为字典值创建自定义对象,并为此类提供可与谓词一起使用的属性:

@interface MyValue : NSObject
@property (nonatomic) NSString *someReference;
@property (nonatomic) NSString *someComment;
@end