2012-04-26 94 views
2

我在排序包含字典及其子字典的nsmutablearray時遇到了一些問題。以下是我的nsmutablearray。我想通過使用actualScore鍵來對此數組進行排序。使用子字典鍵排序

sorteddictioary:(
    { 
    "0:Present and past" =   (
        { 
      SubUnit = "Present simple (\U2018I do\U2019)"; 
      SubUnitExercise = "Exercise 2"; 
      SubUnitExerciseProgress = "<SubUnitExerciseProgress: 0x777d8d0> (entity: TSubUnitExerciseProgress; id: 0x77d2710 <x-coredata://1ADCDF30-EC80-4B40-8A9E-58BA0532D014/TSubUnitExerciseProgress/p1> ; data: {\n actualScore = 6;\n editDate = \"2012-04-25 13:22:38 +0000\";\n subUnitExercise = \"0x7784270 <x-coredata://1ADCDF30-EC80-4B40-8A9E-58BA0532D014/TSubUnitExercise/p2>\";\n time = \"106.246\";\n totalScore = 10;\n})"; 
     } 
    ); 
    "14:Prepositions" =   (
        { 
      SubUnit = "\U2018By\U2019"; 
      SubUnitExercise = "Exercise 2"; 
      SubUnitExerciseProgress = "<SubUnitExerciseProgress: 0x77a9000> (entity: TSubUnitExerciseProgress; id: 0x778d910 <x-coredata://1ADCDF30-EC80-4B40-8A9E-58BA0532D014/TSubUnitExerciseProgress/p2> ; data: {\n actualScore = 7;\n editDate = \"2012-04-26 05:54:45 +0000\";\n subUnitExercise = \"0x77dc1c0 <x-coredata://1ADCDF30-EC80-4B40-8A9E-58BA0532D014/TSubUnitExercise/p278>\";\n time = \"63.06152\";\n totalScore = 10;\n})"; 
     } 
    ); 
    "2:Future" =   (
        { 
      SubUnit = "Present tense (\U2018I am doing\U2019/\U2018I do\U2019) for the future"; 
      SubUnitExercise = "Exercise 1"; 
      SubUnitExerciseProgress = "<SubUnitExerciseProgress: 0x77762d0> (entity: TSubUnitExerciseProgress; id: 0x778d920 <x-coredata://1ADCDF30-EC80-4B40-8A9E-58BA0532D014/TSubUnitExerciseProgress/p3> ; data: {\n actualScore = 0;\n editDate = \"2012-04-26 07:22:23 +0000\";\n subUnitExercise = \"0x81e6e70 <x-coredata://1ADCDF30-EC80-4B40-8A9E-58BA0532D014/TSubUnitExercise/p46>\";\n time = \"113.5866\";\n totalScore = 10;\n})"; 
     } 
    ); 
} 

有誰知道如何排序上面具有子是什麼意思nsmutable陣列。

回答

1

試試這個:

NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"SubUnitExerciseProgress.data.actualScore" 
                  ascending:YES]; 

[initialArray sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]]; 
NSMutableArray* sortedArray = [initialArray mutableCopy]; 
+0

它不工作.. – Ketan 2012-04-27 06:34:08