distinctUnionOfObjects更改数组的顺序

时间:2021-11-29 07:43:29

Below is my original array :

下面是我原来的数组:

{
    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";
}

when I apply distinctUnionOfObjects

当我应用distinctUnionOfObjects时

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

this changes the order giving me resulting array

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

<__NSArrayI>(
Cognitive,
Infant N Toddler
)

It should give

它应该给

<__NSArrayI>(
    Infant N Toddler,
    Cognitive
    )

as per original array order.

按照原始数组顺序。

How do I restrict this order change?

如何限制此订单更改?

1 个解决方案

#1


2  

please try this one

请试试这个

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

#1


2  

please try this one

请试试这个

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