NSPredicate包含内部数组

时间:2015-12-05 08:13:29

标签: ios nsarray nspredicate

我有以下字典

(
{
    "_id" = 100;
    status = 0;
    student =     {
        "__v" = 0;
        "_id" = 565b5fb94e8e3b72793407c0;
        age = 9;
        parentDetail =         (
            myson,
            mywifesson
        );
   };
},
{
    "_id" = 101;
    status = 0;
    student =     {
        "__v" = 0;
        "_id" = 565dfc094afc74bb5a006491;
        age = 9;
        parentDetail =         (
            mywifesson
        );
   };
},
{
    "_id" = 102;
    status = 0;
    student =     {
        "__v" = 0;
        "_id" = 565e000f4afc74bb5a006493;
        age = 9;
        parentDetail =         (
            myson
        );

    };
}
) 

我希望带有内部parentdetails的过滤器项包含字符串" myson"。我尝试了以下谓词,但我得到了过滤数组中的所有3个元素。但实际上它应该只包含第一个和最后一个元素,而不是第二个元素

parentid = @"myson"

[NSPredicate predicateWithFormat:@"ANY student.parentDetail CONTAINS[c] %@", parentid];

1 个答案:

答案 0 :(得分:1)

而不是CONTAINS尝试MATCHES