concept predicate in category ios

appears as: predicates, predicate, predicate
iOS 7 in Action

This is an excerpt from Manning's book iOS 7 in Action.

Next, you’ll learn how to do advanced filtering using predicates.

11.3.3. Filtering results using predicates

Predicates (NSPredicate) can be used to filter arrays unrelated to Core Data. They’re useful when you want to filter data stored in an array. It is, however, the easiest way for you to filter the results that you retrieve when making a fetch request. If you have an understanding of SQL, you can think of it as the conditional when making a SELECT statement. To illustrate this, you’ll create a local array of strings that you’ll use to filter using predicates.

Objective-C Fundamentals

This is an excerpt from Manning's book Objective-C Fundamentals.

Now that you can express a generic predicate condition, you can use it for a number of purposes. A common task is to want to compare a predicate against each object in a collection, such as an NSArray. If you had an array of CTRentalProperty objects called allProperties, for example, you could determine which ones had a rental price greater than $500 by implementing a code snippet similar to the following:

NSPredicate *predicate =
    [NSPredicate predicateWithFormat:@"rentalPrice > 500"];

NSArray *housesThatMatched =
    [allProperties filteredArrayUsingPredicate:predicate];

for (CTRentalProperty *house in housesThatMatched) {
    NSLog(@"%@ matches", house.address);
}

Once you have an NSPredicate expressing your desired condition, NSArray’s filtered-ArrayUsingPredicate: message can be used to evaluate the predicate against each object in the array and return a new array containing only those objects that match the condition. If instead you have a mutable array, a similar filterUsingPredicate: message allows you to remove any objects that don’t match the predicate from an existing array rather than creating a new copy.

iOS 4 in Action: Developing iPhone and iPad Apps

This is an excerpt from Manning's book iOS 4 in Action: Developing iPhone and iPad Apps.

16.4.1. Fetching events with the predicate

A common task is to find out all the events within a certain time period. For example, the user wants to figure out what’s on their Calendar for the next 24 hours. This task can be defined as a predicate in the following listing. Once you have the predicate, you can use a method called eventsMatchingPredicate in the event store to search for qualified events; the return of the search results will be an array of existing events.