【发布时间】:2015-03-07 12:10:58
【问题描述】:
我有这样的 dict 格式。我需要使用字典的dict键中的“quantity1”键对数组进行排序。
array: (
{
brand = Ryul;
productTitle = Any;
quantity = 1;
subBrand = "Ryul INJ";
type = Product;
dict = {
brand1 = Trol;
productTitle1 = Different;
quantity1 = 2;
subBrand1 = "";
type1 = Brand;
};
},
{
brand = Trol;
productTitle = Different;
quantity = 2;
subBrand = "";
type = Brand;
dict = {
brand1 = Trol;
productTitle1 = Different;
quantity1 = 2;
subBrand1 = "";
type1 = Brand;
};
}
)
我使用此代码进行排序:
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"quantity" ascending:YES];
stories=[stories sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
recent = [stories copy];
当我使用“数量”键时,这是有效的。但是当我使用键“quantity1”时它不起作用。
我将如何排序?帮帮我
【问题讨论】:
标签: ios sorting nsarray nsdictionary nssortdescriptor