我知道排序简单的数组,但这很难。我已经在数组索引值中排序了一个数组参数我必须排序,以简单的方式我面对一个更多的数组值所以我混淆了如何排序这种类型的区域这是我的数组这是索引没有0值,在这个数组名称中是TODAY数组值check_in参数我必须排序
{
address = dsfsd;
allergies = Dsf;
annotation = Sdf;
"birth_date" = "0000-00-00";
"category_id" = 2;
"child_id" = 3;
today = {
"check_in" = "7:30 AM";
"check_out" = "7:30 AM";
"child_id" = 3;
"children_schedule_id" = 6;
day = Wednesday;
"on_off" = 1;
};
weight = sdfsd;
"work_hours" = dsfds;
},
这是我的代码
NSSortDescriptor *firstDescriptor = [[NSSortDescriptor alloc] initWithKey:@"today.check_in" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObjects:firstDescriptor, nil];
aryOne = [getData sortedArrayUsingDescriptors:sortDescriptors];
答案 0 :(得分:0)
使用sortedArrayUsingComparator
进行复杂排序。
NSArray *sortedArray = [array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSString *checkIn1 = obj1[@"today"][@"check_in"];
NSString *checkIn2 = obj2[@"today"][@"check_in"];
// You could convert them to dates or times here if you want. Or just compare the strings.
return [checkIn1 compare:checkIn2];
}];