I want to be able to sort a NSArray of objects based on its tag value. The hitch is if the tag is 0, I want it pushed to the end of the array.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"tag" ascending:TRUE];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray = [self.array sortedArrayUsingDescriptors:sortDescriptors];
This returns with all the objects with tags in the front of the index (like it should).
I want a tag value > 0 to be at the front, and all the tag values of 0 at the end.
I though blocks would work, something similar to:
NSArray *sortedArray;
sortedArray = [drinkDetails sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
NSDate *first = [(Person*)a birthDate];
NSDate *second = [(Person*)b birthDate];
return [first compare:second];
}];
that I found in another SO question, but unsure how to add the condition
if (obj.tag == 0) {
// push to end of array
}
Any suggestions?