gpt4 book ai didi

ios - 如何在NSDictionaries的NSArray中将KVC集合运算符用于distinctUnionOfObject?

转载 作者:行者123 更新时间:2023-12-01 16:15:15 25 4
gpt4 key购买 nike

我想从具有值数组的数组字典中获取特定属性的集合。以下是我的数组NSDictionaries:

NSArray *arrGroupsFromServer= @[
@{@"Id": @"7d1021ba-e9be-40c1-a0a1-ad2a2d185b74",@"Name": @"1",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"2"]},
@{@"Id": @"4d830b79-f447-4ad7-8de1-063acf3e242c",@"Name": @"2 TEST",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"3"]},
@{@"Id": @"e481987d-fde8-4a6b-8e05-73877065236d",@"Name": @"CQ",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"4"]},
@{@"Id": @"1a44989d-8b3f-4d8e-8c74-a09c893ca02d",@"Name": @"Intervention group Number",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"5"]},
@{@"Id": @"f10f2fe0-b575-450d-ad63-10d0e8fbe097",@"Name": @"EYFS Caterpillars",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"6"]},
@{@"Id": @"232168c1-73a4-4bbb-b9a2-58e6765e4b2c",@"Name": @"Guided Reading group",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"6"]},
@{@"Id": @"1e9b66f7-c4a7-4774-b062-ce23f587a319",@"Name": @"HfL",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"7"]},
@{@"Id": @"62d53fc5-1fbf-4ebe-bc52-d07ec2680c66",@"Name": @"Red Intervention group",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"8"]},
@{@"Id": @"a70e7429-996a-46ff-aff7-1e1bc5e17c3b",@"Name": @"SEN Green group",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"9"]},
@{@"Id": @"44441c6f-843b-4933-9191-1f3afb23b6cf",@"Name": @"STAT",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"2"]},
@{@"Id": @"04aedc28-4706-49a1-8bbd-9d58179cfd55",@"Name": @"TIST",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"2"]},
@{@"Id": @"c98f592e-4adc-4d9d-a484-ae5b417f11db",@"Name": @"Year 8",@"modifiedDate": @"2016-01-29T15:39:57.000Z",@"PupilIdCollection":@[@"1",@"2"]}
];

现在,我想将 PupilIdCollection属性收集到一个包含所有值的 DistintctUnion的单个数组中,如下所示:
NSArray * PupilIdCollection=@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];(e.g. Order doesn't matter)

我已经尝试过以下方法:
NSArray *arrPupilsIdsFromServer = [arrGroupsFromServer valueForKeyPath:@"@distinctUnionOfObjects.PupilIdCollection"];

但是,这只给了我 PupilIdCollection数组中不同的 arrPupilsIdsFromServer对象,而不是一个具有所有值数组的对象,如下所示:

Screenshot

我只想在KVC的一行代码中输入以下内容:
NSArray * PupilIdCollection=PupilIdCollection=@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];(e.g. Order doesn't matter);(e.g. Order doesn't matter)

这该怎么做?

最佳答案

您需要使用@distinctUnionOfArrays而不是@distinctUnionOfObjects。该运算符有助于展平集合的层次结构,并合并子数组。有关详细信息,请参见开发人员文档。

关于ios - 如何在NSDictionaries的NSArray中将KVC集合运算符用于distinctUnionOfObject?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35475219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com