I have an array that contains a custom class of mine called ‘Game’. Each ‘Game’ contains an NSDate. I would like to reorder my Array based on the dates so that they are in order from newest to oldest. How could I do that? Also, my class ‘Game’ contains an NSString. How could I reorder my Array so that the games are alphabetized?
Share
There’s a REALLY simple way to do this, and that’s with an
NSSortDescriptor:Apple’s already written the sorting code. It just needs to know what properties to sort by. That’s what an
NSSortDescriptorencapsulates. Once you’ve got one, simply give it to the array, and the array give you back a sorted version. (Alternatively, if you have anNSMutableArray, you can sort it in-place using-sortUsingDescriptors:)