数组(时间格式)进行排序

   

//对时间进行排序

 NSSortDescriptor *descriptor = [NSSortDescriptorsortDescriptorWithKey:nilascending:YES];

    NSArray *descriptors = [NSArrayarrayWithObject:descriptor];

    NSArray *myDataArray = [NSArrayarrayWithObjects:@"2016-07-14",@"2016-08-14", @"2016-05-41",@"2015-08-21", @"2016-09-31",@"2016-01-21", nil];

    NSArray *resultArray = [myDataArraysortedArrayUsingDescriptors:descriptors];

    NSLog(@"%@", resultArray);



//对对象模型进行排序

    Student *s1 = [[Student alloc]initWithName:@"Jack" WithAge:18 WithScore:90];

    Student *s2 = [[Student alloc]initWithName:@"Rose" WithAge:28 WithScore:90];

    Student *s3 = [[Student alloc]initWithName:@"Marry" WithAge:23 WithScore:80];

    Student *s4 = [[Student alloc]initWithName:@"Nanny" WithAge:23 WithScore:70];

    Student *s5 = [[Student alloc]initWithName:@"Tom" WithAge:23 WithScore:70];

    NSArray *array = [NSArray arrayWithObjects:s1,s2,s3,s4,s5,nil];

    NSSortDescriptor *sortDescriptor1 = [NSSortDescriptor sortDescriptorWithKey:@"_score" ascending:YES];

    NSSortDescriptor *sortDescriptor2 = [NSSortDescriptor sortDescriptorWithKey:@"_age" ascending:YES];

    NSSortDescriptor *sortDescriptor3 = [NSSortDescriptor sortDescriptorWithKey:@"_name" ascending:YES];

    NSArray *tempArray = [array sortedArrayUsingDescriptors:[NSArray arrayWithObjects:sortDescriptor1,sortDescriptor2,sortDescriptor3,nil]];


猜你喜欢

转载自blog.csdn.net/qq_24143647/article/details/60877908