【发布时间】:2012-08-03 23:08:21
【问题描述】:
我需要使用字典中的键控对象对字典数组进行排序(尽可能接近快速排序),但是由于我的字典的复杂性(键值的数量)和可以返回的数据他们我需要能够根据字典中的几个键值对每个字典进行排序。
例如,如果 array[0], array[1] 中的字典 keyvalue1 相等,则检查 keyvalue2 是否相等,如果是,则继续向下键值列表直到您可以对 array[0 进行排序的两项] & [1] 开启。
我已阅读有关 NSSortDescriptor 并指定属性以与您可以设置升序或降序的位置进行比较,但我不确定这是否可用于实现我想要实现的目标。
我得到了一个我需要做的例子,但它是在我不太熟悉的 delphi 中,但我认为这个例子对我正在尝试做的事情提供了一些见解。
//
Result := AnsiCompareText (left.property1, right.Property1);
if Result <> 0 then Exit;
Result := AnsiCompareText (left.property2, right.Property2);
if Result <> 0 then Exit;
Result := AnsiCompareText (left.property3, right.Property3);
if Result <> 0 then Exit;
Result := AnsiCompareText (left.property4, right.Property4);
if Result <> 0 then Exit;
Result := AnsiCompareText (left.property5, right.Property5);
if Result <> 0 then Exit;
//
希望这会给您一些关于我想要实现的目标的想法,如果您知道目标 C 中的类似解决方案,我很乐意听到任何帮助。 ! :P
【问题讨论】:
标签: iphone ios nsarray nsdictionary nssortdescriptor