如何在ios中排序字典数组

Har*_*abu 1 sorting nsdictionary nsarray nssortdescriptor ios

我有这样的dict formate.我需要在字典的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;
      };
 }
)
Run Code Online (Sandbox Code Playgroud)

我用这个代码进行排序:

    NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"quantity"  ascending:YES];
    stories=[stories sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
   recent = [stories copy];
Run Code Online (Sandbox Code Playgroud)

当我使用键"数量"时,这是有效的.但是当我使用键"quantity1"时,它无法正常工作.

我将如何排序?帮我

Sue*_*uen 11

运用

NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"dict.quantity1"  ascending:YES];
stories=[stories sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
Run Code Online (Sandbox Code Playgroud)

关键是词典.数量1