NSPredicate不使用字典数组

use*_*064 4 cocoa-touch objective-c nsdictionary nsarray 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;
    }
)
Run Code Online (Sandbox Code Playgroud)

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

Dav*_*ong 7

你要:

[NSPredicate predicateWithFormat:@"Status =[cd] 'shipped'"];
Run Code Online (Sandbox Code Playgroud)

要么:

[NSPredicate predicateWithFormat:@"Status =[cd] %@", @"shipped"];
Run Code Online (Sandbox Code Playgroud)

你的问题是你的谓词格式shipped,它应该有'shipped'.缺乏单打引号意味着它试图比较[dictionary valueForKey:@"Status"][dictionary valueForKey:@"shipped"],而不是字符串文字@"shipped".