我在排序包含字典及其子字典的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数组进行排序。
答案 0 :(得分:1)
试试这个:
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"SubUnitExerciseProgress.data.actualScore"
ascending:YES];
[initialArray sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
NSMutableArray* sortedArray = [initialArray mutableCopy];