Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用带有日期的自定义对象对数组排序_Objective C_Ios - Fatal编程技术网

Objective c 使用带有日期的自定义对象对数组排序

Objective c 使用带有日期的自定义对象对数组排序,objective-c,ios,Objective C,Ios,我有一个包含自定义对象的NSArray,这些对象有一个NSString属性,如下所示: @interface Reservation : NSObject{ int _id; NSString *dateAndHour; .... } 例如: Reservation *reserv = [Reservation alloc]init]; reserrv._id=1; reservation.dateAndHour =@"

我有一个包含自定义对象的NSArray,这些对象有一个NSString属性,如下所示:

@interface Reservation : NSObject{

    int _id;    
    NSString *dateAndHour;
    ....
}
例如:

Reservation *reserv = [Reservation alloc]init];
          reserrv._id=1;
          reservation.dateAndHour =@"03/09/1983 07:30 PM";
我有一个包含对象保留的NSArray,现在我想用dateAndHour字段对我的数组进行排序,请告诉我怎么做。
感谢您的回答

您需要将该日期字符串转换为
NSDate
,然后您可以使用
sortDescriptor

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

reservations = [reservations sortedArrayUsingDescriptors:sortDescriptors];

对不起,我不明白你的评论,“巫婆”指的是一个施行巫术的人。“哪个”是你要找的词。