NSPredicate不使用字典数组

时间:2011-05-31 08:42:30

标签: objective-c cocoa-touch nsarray nsdictionary nspredicate

我的NSPredication格式如下:@"Status CONTAINS[cd] shipped"

我有一个字典数组,这是一个例子:

{
        {
        Category = "Category 4";
        Comp = "Category 4";
        Depth = 02;
        Grade = New;
        Length = 02;
        Location = "Thousand Oaks, CA";
        Name = "3ply Mat";
        Owner = "Owner 3";
        PUP = 2;
        Status = Shipped;
        "Unit Number" = 20110507113852351;
        Width = 02;
    },
        {
        Category = "Category 4";
        Comp = "Category 4";
        Depth = 02;
        Grade = New;
        Length = 02;
        Location = "Thousand Oaks, CA";
        Name = "3ply Mat";
        Owner = "Owner 3";
        PUP = 2;
        Status = Shipped;
        "Unit Number" = 20110516094641587;
        Width = 02;
    }
)

但是它返回一个空数组。我究竟做错了什么?感谢

2 个答案:

答案 0 :(得分:7)

你想:

[NSPredicate predicateWithFormat:@"Status =[cd] 'shipped'"];

或者:

[NSPredicate predicateWithFormat:@"Status =[cd] %@", @"shipped"];

您的谓词格式是shipped,而它应该有'shipped'。缺少单引号意味着它试图将[dictionary valueForKey:@"Status"][dictionary valueForKey:@"shipped"]进行比较,而不是将字符串文字@"shipped"进行比较。

答案 1 :(得分:3)

您可以对字符串使用关键字MATCHESCONTAINS等。由于状态不是字符串,我想,您需要像这样检查它,

[NSPredicate predicateWithFormat:@"Status = %d", Shipped];