如何从多个字典词典中搜索数据?

时间:2016-12-12 09:14:07

标签: ios search nspredicate

在我的具有搜索功能的应用程序中,我想从多个键中搜索值 这是我的字典:

 notifications =     (
                {
            "beautician_name" = "ABC";
            "booking_date" = "2016-12-12";
            "date_time" = "2016-12-12 11:27:42";
            discount = 25%;
            "service_name" = Tanning;
            "sub_service_name" = "Spray Tan";
            title = Cancellation;
        },
        {
            "beautician_name" = "PQR";
            "booking_date" = "2016-12-11";
            "date_time" = "2016-12-12 11:27:42";
            discount = 25%;
            "service_name" = hair;
            "sub_service_name" = "Spray Tan";
            title = Cancellation;
        },
        {   
            "beautician_name" = "XYZ";
            "booking_date" = "2016-12-15";
            "date_time" = "2016-12-12 11:27:42";
            discount = 25%;
            "service_name" = film;
            "sub_service_name" = "Spray Tan";
            title = Cancellation;
        }
)

我想搜索来自" beautician_name"," booking_date"," discount"," sub_service_name"这把钥匙。 我想谓词不是任何for循环或等等。 请帮我解决这个问题

1 个答案:

答案 0 :(得分:1)

我还没有测试过,请尝试下面这样的内容。

NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"beautician_name contains[c] %@ OR booking_date contains[c] %@ OR discount contains[c] %@ OR sub_service_name contains[c] %@" ,searchText,searchText,searchText,searchText];
        NSArray *SearchResult = [notifications filteredArrayUsingPredicate:resultPredicate];