Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>NSArray</code>s <code>[filteredArrayUsingPredicate:][1]</code> is the tool for the job.</p> <p>As noted, your <code>listCategories</code> array will contain an array of <code>Category</code> objects with each category containing an array of <code>Element</code> objects.</p> <pre><code>// Retrieve "hotel" Elements NSPredicate *hotelPredicate = [NSPredicate predicateWithFormat:@"name == hotel"]; Category *hotelCategory = [[[listCategories filteredArrayUsingPredicate:hotelPredicate] objectAtIndex: 0] retain]; NSArray *hotels = [[hotelCategory listElements] retain]; // Split the array of Elements based on star value NSPredicate *elementRatingTemplate = [NSPredicate predicateWithFormat:@"stars == $STARS"]; NSPredicate *threeStarPredicate = [elementRatingTemplate predicateWithSubstitutionVariables: [NSDictionary dictionaryWithObject:@"3" forKey:@"STARS"]; NSArray *threeStarHotels = [[hotels filteredArrayUsingPredicate: threeStarPredicate] retain]; NSPredicate *fourStarPredicate = [elementRatingTemplate predicateWithSubstitutionVariables: [NSDictionary dictionaryWithObject:@"4" forKey:@"STARS"]; NSArray *fourStarHotels = [[hotels filteredArrayUsingPredicate: fourStarPredicate] retain]; NSPredicate *fiveStarPredicate = [elementRatingTemplate predicateWithSubstitutionVariables: [NSDictionary dictionaryWithObject:@"5" forKey:@"STARS"]; NSArray *fiveStarHotels = [[hotels filteredArrayUsingPredicate: fiveStarPredicate] retain]; // Do something with the filtered arrays // Clean up retained objects. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload