I'm using an NSSortDescriptor to sort NSDate objects in an ascending order. However, I need nil dates to be at the bottom of the list, whereas at the moment they come at the top.
In the end I have decided that having nil values is not a good idea and if I want what were nil value to appear at the bottom of the ascending list I should set the dates to [NSDate distantFuture] and them check for this before displaying them. It turns out this makes more semantic sense in within the applications as well.
Looks like you already have a solution, but for anyone else looking to still use nil NSDates, and have them at the bottom, I use the following code where I sort descending, and then reverse the order of the objects sent to the compare.
_sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"dueDate"
ascending:NO
comparator:^NSComparisonResult(id obj1, id obj2) {
return [obj2 compare:obj1];
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With