【问题标题】:Search NSArray of NSDictionary. How to find using NSPredicate?搜索 NSDictionary 的 NSArray。如何使用 NSPredicate 查找?
【发布时间】:2017-01-31 06:14:14
【问题描述】:

我有一个NSArray。它在每个索引中都有一个或多个NSDictionary。根据搜索输入,我想检查它是否包含 contact_Labelcontact_detail 字典中的值。它看起来像这样:

(
  {
     "contact_detail" =     {
          "contact_is_in_phone" = 1;
          "contact_Label" = "Tyler Globussoft";
          "contact_displayname" = "Suzan Arohh";
     },
     "last_msg_details" =     {
           .....
     };
  },
  {
  }
);

我就这样累了。但没有得到结果。

NSArray *contacts = self.dataArray; //your array of NSDictionary objects
NSPredicate *filter = [NSPredicate predicateWithFormat:@"contact_Label = %@",stringValue];
NSArray *filteredContacts = [contacts filteredArrayUsingPredicate:filter];

【问题讨论】:

标签: ios objective-c nspredicate


【解决方案1】:

你可以使用

NSArray *contacts = self.dataArray; //your array of NSDictionary objects
NSPredicate *filter = [NSPredicate predicateWithFormat:@"contact_detail.contact_Label = %@",stringValue];
NSArray *filteredContacts = [contacts filteredArrayUsingPredicate:filter];

编码愉快...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 2012-05-17
    • 2011-08-16
    • 2010-10-31
    • 1970-01-01
    相关资源
    最近更新 更多