When I sort the array using sortedArrayUsingSelector method , all works fine except it brings records with BLANK names at the top of array . I don’t want records with BLANK names on top of array instead they should be last in the array. How can I implement this? Here is my code
self.tempArray = [NSMutableArray arrayWithArray:[self.tempArray sortedArrayUsingSelector:@selector(compare:)]];
I am sorting the array on first name of user. Here is code of compare method
-(NSComparisonResult)compare:(User*)user {
return [self.firstName compare:user.firstName];
}
Any kind of help is highly appreciated. Thanks.
Change your comparison method so that you treat empty names differently.
You can probably write this in fewer lines of code but I have left it like this for readability.
nilcannot be used as a comparator for string comparisons.Currently it is (correctly) sorting blanks to the top, since they are come before populated strings in an alphanumeric sort.