NSPredicate 不适用于字典数组
我有一个 NSPredicate ,其格式如下:@"Status CONTAINS[cd] returned"
我有一个字典数组,这是一个示例:
{
{
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;
}
)
但它返回一个空数组。我做错了什么?谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要:
或者:
您的问题是您的谓词格式已
shipped
,而它本应具有'shipped'
。缺少单引号意味着它试图将[dictionary valueForKey:@"Status"]
与[dictionary valueForKey:@"shipped"]
进行比较,而不是与字符串进行比较文字@“已发货”
。You want:
Or:
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"
.您可以对字符串使用关键字
MATCHES
、CONTAINS
等。由于 Status 不是字符串,我想您需要这样检查,You can use the keywords
MATCHES
,CONTAINS
etc., against strings. As Status is not a string, I guess, you need to check it like this,