使用NSPredicate按值过滤NSDictionary

时间:2014-03-26 07:39:54

标签: ios objective-c nsdictionary nspredicate

我有NSDictionary这样:

{
    1 = A;
    11 = AB;
    19 = ABC;
    2 = ABCD;
    3 = ABCDE;
    4 = ABCDEF;
    5 = ABCDEFG;
    6 = ABCDEFGH;
    7 = ABCDEFGHI;
    9 = ABCDEFGHIJ;
}

现在我想用谓词过滤Dictionary,以返回值开始的数组,例如用" ABCD"。 Key是一个ID(字符串),Value是string类型。

所以结果应该是

{
    ABCD;
    ABCDE;
    ABCDEF;
    ABCDEFG;
    ABCDEFGH;
    ABCDEFGHI;
    ABCDEFGHIJ;
}

NSPredicate看起来如何?

1 个答案:

答案 0 :(得分:2)

Predicate将如下所示:

NSPredicate * predicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[c] %@", @"ABCD"];