0

i have an NSArray which contains custom objects, the objects have an NSString property, like this :

@interface Reservation : NSObject{

    int _id;    
    NSString *dateAndHour;
    ....
}

example :

Reservation *reserv = [Reservation alloc]init];
          reserrv._id=1;
          reservation.dateAndHour =@"03/09/1983 07:30 PM";

I have an NSArray which contains objects Reservation, now i would like to sort my array with the field dateAndHour, how i can do this please. thanks for your aswer

Terry Wilcox
  • 9,010
  • 1
  • 34
  • 36
samir
  • 4,501
  • 6
  • 49
  • 76

1 Answers1

0

You need to convert that date string into an NSDate and then you can just use a sortDescriptor

NSSortDescriptor *dateSort = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:dateSort];

reservations = [reservations sortedArrayUsingDescriptors:sortDescriptors];
Paul.s
  • 38,494
  • 5
  • 70
  • 88