How to establish secondary NSSortDescriptor sort key?

前端 未结 2 1079
长情又很酷
长情又很酷 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]];
    
    0 讨论(0)
  • 2021-02-20 10:12

    Notice that you are passing an array of sort descriptors. Simply create another descriptor for firstname and create the array with both descriptors. They will be applied in the order of the array.

    0 讨论(0)
提交回复
热议问题