I’m using NSSortDescriptor to sort an NSArray of NSDictionary items. Works great, just what I needed… except that I’d like for the dictionary items that have blank values for my sort key to show up at the end of the sorted list. Is there a way to easily accomplish this? Or will I have to create some custom sorting functions? And no, I don’t want to just set it to DESC order… I’d like sorted results to look like A, A, B, B, C, blanks, blank.
I’m using NSSortDescriptor to sort an NSArray of NSDictionary items. Works great, just what
Share
Figured this out after seeing another example using a custom comparison. Here is the code I ended up with:
So the comparer returns NSOrderedSame if both strings are empty… calls the regular comparison function if both strings are non-empty… if only one string is empty, it reverses the normal order of that comparison. Voila!