- 创建两个Person对象,并把它们放入数组,按年龄升序排序
Person *person1 = [[Person alloc] init];
Person *person2 = [[Person alloc] init];
person1.age = @"8";
person2.age = @"5";
NSMutableArray *arr = [NSMutableArray arrayWithObjects: person1, person2, nil];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"age" ascending:YES];
NSArray *newArr = [topArr sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
此时newArr中,是以person2, person1的顺序存储。
网友评论