How to establish secondary NSSortDescriptor sort key?

前端 未结 2 1078
长情又很酷
长情又很酷 2021-02-20 09:41

I have successfully sorted the data I have by my sort key lastName, but I want to know how to sort by lastName, and then by firstName. He

2条回答
  •  攒了一身酷
    2021-02-20 09:57

    NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];
    NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];
    
    [request setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor1, sortDescriptor2, nil]];
    

提交回复
热议问题