我有一个带有对象的数组,我希望将Header设置为层次结构值但是在数组层次结构中,vale在两个对象中是相同的,现在我想设置单个相同层次结构名称的标题,并在单个部分下添加具有相同层次结构名称的所有对象。
(
{
activity = 3465;
code = ASWAAA;
hierarchy = "Vodafone1 > Vodafone12 > rerer > hhkk > VIdeosocndf1";
name = TerritoryAcc;
},
{
activity = 3470;
code = DEQWQQ;
hierarchy = Collection;
name = "Reverse Dependency";
},
{
activity = 3489;
code = SASWER;
hierarchy = "Admission Form > Army School";
name = BIOCOMM;
},
{
activity = 3493;
code = SDFREW;
hierarchy = Collection;
name = Rating;
}
)
答案 0 :(得分:1)
您可以使用词典分组初始值设定项创建包含分组对象的词典:
let dic = Dictionary(grouping: array) { (element) in
return element["hierarchy"]!
}
然后每个dic键都是一个节头名称,相应的值是与此节相关的对象数组。