Below is a bit of my recent work code that changes the order of sorting based on the class instance variable m_seatQuality value:
featuresArray = [[unsortedFeaturesArray sortedArrayUsingComparator: ^(id a, id b) {
DMSeatFeature *first = ( DMSeatFeature* ) a;
DMSeatFeature *second = ( DMSeatFeature* ) b;
if ( first.quality == second.quality )
return NSOrderedSame;
else
{
if ( eSeatQualityGreen == m_seatQuality
|| eSeatQualityYellowGreen == m_seatQuality
|| eSeatQualityDefault == m_seatQuality )
{
if ( first.quality < second.quality )
return NSOrderedAscending;
else
return NSOrderedDescending;
}
else // eSeatQualityRed || eSeatQualityYellow
{
if ( first.quality > second.quality )
return NSOrderedAscending;
else
return NSOrderedDescending;
}
}
}] retain];
Немає коментарів:
Дописати коментар