如何建立辅助NSSortDescriptor排序键?
我已成功按排序键 lastName
对数据进行排序,但我想知道如何按 lastName
排序,然后按 firstName
排序。这是我用来按 lastName
排序的代码
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
如何添加 firstName
的辅助排序键?
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]];
How do I add the secondary sort key of firstName
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,您正在传递一个排序描述符数组。只需为名字创建另一个描述符并使用这两个描述符创建数组即可。它们将按数组的顺序应用。
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.