2015-01-09 85 views
1

我有像這樣的字謎。我需要使用字典的dict鍵中的「quantity1」鍵對數組進行排序。如何排序在ios字典陣列

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」鍵時它不起作用。

我將如何排序?使用

NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"dict.quantity1" ascending:YES]; 
stories=[stories sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]]; 

關鍵是字典幫我

回答

11

。數量1

+0

謝謝..這工作正常。 –

+0

@HariBabu如果他們這樣做,你應該稱讚Suen幫助解決你的問題。 – soulshined