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.
+2
A:
Of course, I should use
initWithKey:ascending:selector:
and write my own comparison selector
Daniel Wood
2010-01-07 15:41:02
Exactly. Do you custom logic to handle nil values and then call [myNSDateInstance compare:secondDate]; if second date is non nil.
Corey Floyd
2010-01-07 17:40:59
That won't help, since `compare:` will be sent to the NSDate instances; if `nil` ends up the receiver, the result will be `NSOrderedSame`, and if the receiver is not `nil` but the argument is, I don't think any specific result is guaranteed.
Peter Hosey
2010-01-07 18:07:43
+1
A:
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.
Daniel Wood
2010-01-07 16:36:53