【问题标题】:NSSortdescriptor, finding the path to the key I wish to use for sortingNSSortdescriptor,找到我希望用于排序的键的路径
【发布时间】:2010-05-19 14:28:03
【问题描述】:

我正在使用 NSSortdescriptor 对 NSArray 的集合进行排序,然后我遇到了一个案例,其中要排序的特定 NSArray 包含一个包含 NSDictionary 的 NSDictionary。 我想从与最后一个字典中的键配对的字符串中进行排序。

这就是我引用字符串的方式:

NSDictionary *productDict = [MyArray objectAtIndex:index];
NSString *dealerName = [[productDict objectForKey:@"dealer"] objectForKey:@"name"];

如何在我的 NSSortdescriptor 中使用 dealerName 对数组进行排序?

NSSortDescriptor * sortDesc = [[NSSortDescriptor alloc] initWithKey:/* ? */  ascending:YES];
sortedDealerArray = [value sortedArrayUsingDescriptors:sortDesc];
[sortDesc release];

希望有人可以帮助我了解如何根据其他对象内部对象内部的键进行排序:)

谢谢。

【问题讨论】:

  • 键路径跨字典键工作,所以假设你有一个产品字典的 NSArray,看起来你想要的路径只是 @"dealer.name",但我认为这不起作用?

标签: iphone nsdictionary nssortdescriptor


【解决方案1】:

其实warrenM 是对的。您可以只使用键路径。 @"dealer.name" 应该适用于上述情况。

【讨论】:

    猜你喜欢
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多