0

My object "Event" has got a property NSDate. I fill a NSMutableArray with "Event" objects. Is there a way to order by NSDate the members of my NSMutableArray? Thank you all.

Ales
  • 19
  • 8

1 Answers1

1

Assuming you have an NSMutableArray

[yourArray sortUsingComparator:^NSComparisonResult(Event *obj1, Event *obj2){
     return [obj1.date compare:obj2.date];
}];

Otherwise :

NSArray sortedArray = [yourArray sortedArrayUsingComparator:^NSComparisonResult(Event *obj1, Event *obj2) {
    return [obj1.date compare:obj2.date];
}];
streem
  • 8,835
  • 5
  • 28
  • 40