What I want to do seems pretty simple, but I can\'t find any answers on the web. I have an NSMutableArray
of objects, and let\'s say they are \'Person\' objects
Your Person
objects need to implement a method, say compare:
which takes another Person
object, and return NSComparisonResult
according to the relationship between the 2 objects.
Then you would call sortedArrayUsingSelector:
with @selector(compare:)
and it should be done.
There are other ways, but as far as I know there is no Cocoa-equiv of the Comparable
interface. Using sortedArrayUsingSelector:
is probably the most painless way to do it.