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 数组之上进行排序。

4

1 回答 1

1

尝试这个 :

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

[initialArray sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
NSMutableArray* sortedArray = [initialArray mutableCopy];
于 2012-04-26T10:40:49.440 回答