Skip to content

How To Do Amazingly Simple Searches With NSArray & NSPredicate

Good, straight forward article on NSPredicate use…

How To Do Amazingly Simple Searches With NSArray & NSPredicate.

Here are the steps required to search arrays with NSPredicate:

  • Find or create an NSArray full of objects with interesting properties
  • Create an NSPredicate object with the search query that you want to use
  • You can use this NSPredicate object to either filter the array or create a new array with a subset of data
  • [code]
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"dept == Dev"];
    NSArray *devEmps = [emps filteredArrayUsingPredicate:predicate];

    [/code]