NSPredicate不使用字典数组 [英] NSPredicate not working with array of dictionaries
本文介绍了NSPredicate不使用字典数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个NSPredication,格式如下: @Status CONTAINS [cd] shipped
I have an NSPredication with format like this:@"Status CONTAINS[cd] shipped"
有一个字典数组,这里有一个例子:
I have an array of dictionary, here's an example:
{
{
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;
}
)
但它返回一个空数组。我做错了什么?感谢
But it's returning an empty array. What am I doing wrong? Thanks
推荐答案
您想要:
[NSPredicate predicateWithFormat:@"Status =[cd] 'shipped'"];
或:
[NSPredicate predicateWithFormat:@"Status =[cd] %@", @"shipped"];
您的问题是您的谓词格式发货
,当它应该有'shipped'
。缺少单引号意味着它试图比较 [dictionary valueForKey:@Status]
到 [dictionary valueForKey:@shipped]
,而不是字符串文字 @shipped
。
Your problem was that your predicate format had shipped
, when it should've had 'shipped'
. The lack of singles quotes meant it was trying to compare [dictionary valueForKey:@"Status"]
to [dictionary valueForKey:@"shipped"]
, instead of to the string literal @"shipped"
.
这篇关于NSPredicate不使用字典数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文