distinctUnionOfObjects更改数组的顺序

时间:2017-06-08 05:05:28

标签: ios objective-c arrays sorting nsmutablearray

以下是我原来的数组:

{
    FilePath = "Selfcare.jpg";
    ModuleId = 18;
    ModuleName = "Infant N Toddler";
    SkillLevelID = 59;
    SkillLevelName = "Self Care";
},
{
    FilePath = "Preschool.jpg";
    ModuleId = 18;
    ModuleName = "Infant N Toddler";
    SkillLevelID = 60;
    SkillLevelName = "Preschool Readiness";
},
{
    FilePath = "Learning_Primary.jpg";
    ModuleId = 22;
    ModuleName = Cognitive;
    SkillLevelID = 71;
    SkillLevelName = "Learning Readiness - Primary Skills";
},
{
    FilePath = "PreAcad_Primary.jpg";
    ModuleId = 22;
    ModuleName = Cognitive;
    SkillLevelID = 72;
    SkillLevelName = "Pre-Academics: Primary Skills";
}

当我应用distinctUnionOfObjects

NSArray *curriculums = [array valueForKeyPath:@"@distinctUnionOfObjects.ModuleName"];

这改变了给出结果数组的顺序

<__NSArrayI>(
Cognitive,
Infant N Toddler
)

应该给出

<__NSArrayI>(
    Infant N Toddler,
    Cognitive
    )

按照原始数组顺序。

如何限制此订单更改?

1 个答案:

答案 0 :(得分:2)

请尝试这个

NSArray *orderedSet = [[NSOrderedSet orderedSetWithArray:[people valueForKey:@"ModuleName"]] array];