Multiple sort descriptors

In the below example we have an array of review objects which have a "rating" and "votes" property. We want to sort first by ratings and then by votes (where two review objects have the same rating we want to give preference to the one with the most votes).

NSSortDescriptor *sortRating = [[NSSortDescriptor alloc] initWithKey:@"rating" ascending:NO];
NSSortDescriptor *sortVotes = [[NSSortDescriptor alloc] initWithKey:@"votes" ascending:NO];

NSArray *sortedArray = [unsortedArray sortedArrayUsingDescriptors:[NSArray arrayWithObjects:sortRating, sortVotes, nil]]; //the nil here is important, it tells the compiler that it has reached the end of the list

By switching the order of the of the NSSortDescriptors, we alter the weight of the sortDescriptors i.e. if we wanted votes to take preference over ratings we would only need to change one line in the above example to:

NSArray *sortedArray = [unsortedArray sortedArrayUsingDescriptors:[NSArray arrayWithObjects:sortVotes, sortRating, nil]];