如何建立辅助NSSortDescriptor排序键

如何建立辅助NSSortDescriptor排序键

本文介绍了如何建立辅助NSSortDescriptor排序键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按排序键 lastName 成功排序了我的数据,但我想知道如何按 lastName ,然后按 firstName 。这是我用来排序的代码 lastName

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. Here is the code I used to sort by lastName

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];

如何添加 firstName的辅助排序键

推荐答案

NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];
NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];

[request setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor1, sortDescriptor2, nil]];

这篇关于如何建立辅助NSSortDescriptor排序键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:22