NSCompoundPredicate не фильтрующий массив

Чтобы протестировать приложение для поиска ресторанов, я включил 4 тестовых ресторана в файл JSON, которые корректно заполняют представление таблицы соответствующими свойствами. В 3 текстовых полях я фильтрую массив по имени, средней цене и рейтингу, но когда я передаю его методу, отфильтрованный зарегистрированный массив не фильтруется. Хотя я не вижу ничего плохого в моем коде предиката, есть идеи? Спасибо!

- (void)searchRestaurantsWithName:(NSString *)name price:(int)price andRating:(int)rating  completion:(void (^)(NSArray *restaurants))completion {

NSMutableArray *restaurantsToFilter = [[RestaurantController sharedInstance].restaurants mutableCopy];

NSPredicate *namePredicate = [NSPredicate predicateWithFormat:@"name CONTAINS[c] %@", name];
NSPredicate *pricePredicate = [NSPredicate predicateWithFormat:@"price < %i", price];
NSPredicate *ratingPredicate = [NSPredicate predicateWithFormat:@"rating > %i", rating];

NSPredicate *compoundPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[namePredicate, pricePredicate, ratingPredicate]];

NSArray *filteredArray = [restaurantsToFilter filteredArrayUsingPredicate:compoundPredicate];

completion(filteredArray);

}

Метод, который вызывает кнопка

- (void)filterArray {

[self searchRestaurantsWithName:self.nameTextField.text price:[self.priceTextField.text intValue]  andRating:[self.ratingTextField.text intValue] completion:^(NSArray *restaurants) {

    [self.tableView reloadData];

    NSLog(@"%@", restaurants);

}];
}

0 ответов

Другие вопросы по тегам