NSSortdescriptor,查找我希望用于排序的键的路径
我正在使用 NSSortdescriptor 对 NSArray 集合进行排序,然后我遇到了一种情况,其中要排序的特定 NSArray 包含一个 NSDictionary,而该 NSDictionary 又包含一个 NSDictionary。 我想从与最后一个字典中的键配对的字符串进行排序。
这就是我引用字符串的方式:
NSDictionary *productDict = [MyArray objectAtIndex:index];
NSString *dealerName = [[productDict objectForKey:@"dealer"] objectForKey:@"name"];
How will I use the dealerName
in my NSSortdescriptor to sort the array?
NSSortDescriptor * sortDesc = [[NSSortDescriptor alloc] initWithKey:/* ? */ ascending:YES];
sortedDealerArray = [value sortedArrayUsingDescriptors:sortDesc];
[sortDesc release];
希望有人可以帮助我如何根据其他对象内的对象内的键进行排序:)
谢谢。
I am using an NSSortdescriptor to sort a collection of NSArrays, I then came across a case where the particular NSArray to be sorted contains an NSDictionary who contains an NSDictionary.
I would like to sort from the string paired with a key in the last dictionary.
This is how I would reference the string:
NSDictionary *productDict = [MyArray objectAtIndex:index];
NSString *dealerName = [[productDict objectForKey:@"dealer"] objectForKey:@"name"];
How would I use the dealerName
in my NSSortdescriptor to sort the array?
NSSortDescriptor * sortDesc = [[NSSortDescriptor alloc] initWithKey:/* ? */ ascending:YES];
sortedDealerArray = [value sortedArrayUsingDescriptors:sortDesc];
[sortDesc release];
Hope someone could help me a bit with how I go about sorting according to keys inside objects inside other objects:)
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上沃伦M是对的。您可以只使用键路径。 @“dealer.name”应该适用于上面的情况。
actually warrenM is right. You can just use keypaths. @"dealer.name" should work for above.